Xiaochong Zhang



In this post, we will go through the following functions: insert() del remove() pop() index() in() count() join() sort() sorted() copy() 1, insert(): add an item by offset with insert() function. list.insert(index, value), if the index is out of the range of the list, the insert() function will play the same functionality with append(), add […]


1, List is a mutable in Python. 2, You can change list in place, free to add, delete, and update element in list. 3, The same value can occur more than one time in Python’s list. 4, List can contain different elements, eg my_list1 = [“Hello Python”, 1, 3.52]

101Python-Variables, Built-in types && String2

we will demo the following string’s functions slice, split, join, strip, replace. The code as following:

101Python-Variables, Built-in types && String1

Python has some built-in types, such as: integers, boolean, string, and float. Python is a strongly typed language. For example, define each type variable as following:

Note: In python2, the integer is 32 bit large, which means it scales from -2147483648 to 2147483647. For binary base, we use 0b10 which means 2 Type conversion: […]

Implement Trie

208. Implement Trie (Prefix Tree) My Submissions Question Total Accepted: 25441 Total Submissions: 101901 Difficulty: Medium Implement a trie with insert, search, and startsWith methods. Note: You may assume that all inputs are consist of lowercase letters a-z.

Palindrome Linked List

Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) time and O(1) space?

virtual function and polymorphism in C++

Derived class’s function is called via used the base pointer calling. virtual function is called according to the object type referred; not decided via the pointer type. in the other words, virtual functions is decided at the runtime; not compile time. an example of virtual functions and polymorphism as following:

vtable: A table of […]

Implement Queue using Stacks

232. Implement Queue using Stacks My Submissions Question Total Accepted: 27548 Total Submissions: 81429 Difficulty: Easy Implement the following operations of a queue using stacks. push(x) — Push element x to the back of queue. pop() — Removes the element from in front of queue. peek() — Get the front element. empty() — Return whether […]

Ugly Number

Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7. Note that 1 is typically treated as an ugly number.

Happy Number

Write an algorithm to determine if a number is “happy”. A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly […]

Previous Posts

Theme created by thememotive.com. Powered by WordPress.org.