# Tag Archives: sort

## Find Celebrity

This one is from leetcode. http://www.cnblogs.com/easonliu/p/4785253.html Suppose you are at a party with n people (labeled from 0 to n – 1) and among them, there may exist one celebrity. The definition of a celebrity is that all the other n – 1people know him/her but he/she does not know any of them. Now you… Read More »

## Gray code

The original problem is from leetcode: https://leetcode.com/problems/gray-code/ And I found a very good solution from Wolfram: The code is called reflected because it can be generated in the following manner. Take the Gray code 0, 1. Write it forwards, then backwards: 0, 1, 1, 0. Then prepend 0s to the first half and 1s to… Read More »

## Wiggle Sort II

This one is from leetcode: https://leetcode.com/problems/wiggle-sort-ii/ Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]… Example: (1) Given nums = [1, 5, 1, 1, 6, 4], one possible answer is [1, 4, 1, 5, 1, 6]. (2) Given nums = [1, 3, 2, 2, 3, 1], one possible answer… Read More »