From Chen's Wiki

Jump to: navigation, search


<Rotate Array>:

			self.reverse(nums, 0, size-k-1)
			self.reverse(nums, size-k, size-1)
			self.reverse(nums, 0, size-1)

Linked list

<linked list cycle>: slow/fast pointer: if no cycle, fast gets to None. Else, fast will meet slow.

		while fast and
			slow =
			fast =
			if slow == fast:
				return True


<Candy>: Two pass

		for i in range(1, N):
			if ratings[i] > ratings[i-1]:
				C[i] = C[i-1]+1
		for i in range(N-2,-1,-1):
			if ratings[i+1]<ratings[i] and C[i+1] >= C[i]:
				C[i] = C[i+1]+1