My code can be viewed in my github: Proverbs Github.
The following difficulty is defined by myself.

4sum(medium)

We can apply the same method of enumerating the first 2 positions as 3sum to this problem and the time complexity will be O(n^3).
Sum of four numbers is the sum of two pairs. Thus, another way is to use a map to save the sums of all pairs of numbers and use a set to store corresponding pairs.
To avoid duplications, we can stipulate that numbers in the first pair should not greater than numbers in the second pair.
And to avoid cases like [-1, -1, -1, -1], sum=4, we should check if the combination of two pairs is available.

  • Time complexity: O(n^2logn) if using set, O(n^2) if using unordered_set(need to customize hash function).
  • Space complexity: O(n^2logn) if using set.

all-oone-data-structure(hard)

I have mentioned that: inc/dec by 1 --> linked list before.

  • Time complexity: O(1).
  • Space complexity: O(n).

count-primes(easy)

Sieve method to check primes.

  • Time complexity: O(n).
  • Space complexity: O(n).

design-log-storage-system(medium)

Set(customized comparator) + binary search.

  • Time complexity: O(logn) for put function, O(result_size) for retrieve function.
  • Space complexity: O(nlogn).

frog-jump(medium)

DP using recurrence(递推).

  • Time complexity: O(n^2).
  • Space complexity: O(n^2).

is-graph-bipartite(easy)

Coloring using two colors.

  • Time complexity: O(n).
  • Space complexity: O(n).

isomorphic-strings(easy)

s can mapping to t, t can mapping to s.

  • Time complexity: O(n).
  • Space complexity: O(n).

simplify-path(easy)

Stack for ...

  • Time complexity: O(n).
  • Space complexity: O(n).

string-compression(easy)

The compressed string will be always shorter than(or equal to) the its original string.

  • Time complexity: O(n).
  • Space complexity: O(1) in-place.

swap-nodes-in-pairs(easy)

Operations of linked list.

  • Time complexity: O(n).
  • Space complexity: O(1) in-place.

to-lower-case(easy)

  • Time complexity: O(n).
  • Space complexity: O(n).

two-sum-ii-input-array-is-sorted(easy)

Two pointers. Each time left pointer moves right, right pointer will never move right.

  • Time complexity: O(n).
  • Space complexity: O(1).

validate-ip-address(easy)

Be careful of some special cases.

  • Time complexity: O(n).
  • Space complexity: O(1).

zigzag-conversion(easy)

The straightforward way is to put all letters to their 2D coordinates.
But the smarter way is to compute the coordinates directly, O(length).

  • Time complexity: O(num * length) for the first way.
  • Space complexity: O(num * length) for the first way.

course-schedule-ii(easy)

Topological sort.

  • TIme complexity: O(n).
  • Space complexity: O(n).

wiggle-sort-ii(hard)

For wiggle-sort, we can just put those less than or equal to the median to even slots and those greater or equal to the median to odd slots.
However, it is not correct for this problem because the relationship between two consecutive numbers is strict.
For example, the solution of [4,5,5,6] is [5,6,4,5].
To get wiggle sort, you want to put the number in the following way such that

(1) elements smaller than the ‘median’ are put into the last even slots
(2) elements larger than the ‘median’ are put into the first odd slots
(3) the medians are put into the remaining slots.

ref.

And the solution use three-way-partition and virtual indexing which is quite brilliant.