摘要:
Description Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. Note: The algorithm should run in linear time and 阅读全文
摘要:
Description Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may ass 阅读全文
摘要:
Description Given a non negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note that the row index starts from 0. In Pa 阅读全文
摘要:
Description Let's call any (contiguous) subarray B (of A) a mountain if the following properties hold: B.length = 3 There exists some 0 B[i+1] ... B[B 阅读全文
摘要:
Description Given an unsorted integer array, find the smallest missing positive integer. Example 1: Example 2: Example 3: Note: Your algorithm should 阅读全文
摘要:
Description Shuffle a set of numbers without duplicates. Example: 思路 分析洗牌算法正确性的准则:产生的结果必须有 n! 种可能,否则就是错误的。这个很好解释,因为一个长度为 n 的数组的全排列就有 n! 种,也就是说打乱结果总共有 阅读全文
摘要:
Description Given an array, rotate the array to the right by k steps, where k is non negative. Example 1: Example 2: Note: Try to come up as many solu 阅读全文
摘要:
Description 思路 老年人回炉重造第6天。 这道题和 442 是同类型的题,比较tricky,要求时间复杂度 ,no extra space(题目补充说明了待返回的数组不算在 extra space 里,所以可以开辟一个数组保存算法的结果) 本题的难点之一是如何正确理解题目,关键信息有两个 阅读全文
摘要:
Description Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements tha 阅读全文