277. Find the Celebrity
摘要: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 tha
阅读全文
posted @
2016-10-13 12:08
Machelsky
阅读(190)
推荐(0)
187. Repeated DNA Sequences
摘要:All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to
阅读全文
posted @
2016-10-13 11:40
Machelsky
阅读(198)
推荐(0)
172. Factorial Trailing Zeroes
摘要:Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity. 思路:有多少个0就是有多少个5. 零的产生就是5
阅读全文
posted @
2016-10-13 10:31
Machelsky
阅读(128)
推荐(0)
48. Rotate Image
摘要:You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Follow up:Could you do this in-place? 思路:对角线对称呼唤,Y
阅读全文
posted @
2016-10-13 10:15
Machelsky
阅读(160)
推荐(0)
154. Find Minimum in Rotated Sorted Array II
摘要:Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed? Would this affect the run-time complexity? How and why? Suppose a
阅读全文
posted @
2016-10-13 09:36
Machelsky
阅读(157)
推荐(0)
205. Isomorphic Strings
摘要:Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replaced to get t. All occurrenc
阅读全文
posted @
2016-10-12 16:54
Machelsky
阅读(157)
推荐(0)
292. Nim Game
摘要:You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 ston
阅读全文
posted @
2016-10-12 16:35
Machelsky
阅读(118)
推荐(0)
86. Partition List
摘要:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the
阅读全文
posted @
2016-10-12 15:55
Machelsky
阅读(197)
推荐(0)
80. Remove Duplicates from Sorted Array II
摘要:Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For example,Given sorted array nums = [1,1,1,2,2,3], Your function sho
阅读全文
posted @
2016-10-12 15:06
Machelsky
阅读(158)
推荐(0)
263. 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 exa
阅读全文
posted @
2016-10-12 14:56
Machelsky
阅读(131)
推荐(0)
389. Find the Difference
摘要:Given two strings s and t which consist of only lowercase letters. String t is generated by random shuffling string s and then add one more letter at
阅读全文
posted @
2016-10-11 16:00
Machelsky
阅读(187)
推荐(0)
173. Binary Search Tree Iterato
摘要:Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST. Calling next() will return the n
阅读全文
posted @
2016-10-11 15:50
Machelsky
阅读(100)
推荐(0)
98. Validate Binary Search Tree
摘要:Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only
阅读全文
posted @
2016-10-11 15:22
Machelsky
阅读(142)
推荐(0)
58. Length of Last Word
摘要:Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string. If the last word
阅读全文
posted @
2016-10-11 14:53
Machelsky
阅读(118)
推荐(0)
203. Remove Linked List Elements
摘要:Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --
阅读全文
posted @
2016-10-11 13:18
Machelsky
阅读(85)
推荐(0)
复习4
摘要:66. Plus One: 只需考虑数字是不是9即可,不是9,直接加1输出,是9,就继续检查更新。如果结束循环还不输出,就是全9情况,建新array输出第一位为1.
阅读全文
posted @
2016-10-11 12:03
Machelsky
阅读(73)
推荐(0)
概念题
摘要:1. HashMap 和 HashTable 转:http://www.cnblogs.com/devinzhang/archive/2012/01/13/2321481.html
阅读全文
posted @
2016-10-11 08:24
Machelsky
阅读(96)
推荐(0)
73. Set Matrix Zeroes
摘要:Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. 122/145 思路:遍历整个matrix,找到element是0的时候,记录对应的row和column。有两个
阅读全文
posted @
2016-10-10 13:04
Machelsky
阅读(93)
推荐(0)
268. Missing Number
摘要:Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. For example,Given nums = [0, 1,
阅读全文
posted @
2016-10-10 12:35
Machelsky
阅读(121)
推荐(0)
200. Number of Islands
摘要:Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacen
阅读全文
posted @
2016-10-10 07:35
Machelsky
阅读(142)
推荐(0)
28. Implement strStr()
摘要:Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 思路:对应检查char是否一样,不一样直接跳出检
阅读全文
posted @
2016-10-10 07:19
Machelsky
阅读(315)
推荐(0)
345. Reverse Vowels of a String
摘要:Write a function that takes a string as input and reverse only the vowels of a string. Example 1:Given s = "hello", return "holle". Example 2:Given s
阅读全文
posted @
2016-10-10 07:04
Machelsky
阅读(146)
推荐(0)
复习3
摘要:160. Intersection of Two Linked Lists 1.各自扫一遍list找到第一个相同节点 2.各自扫一遍,记录长度。将长的缩小到跟短的一样,相同长度的情况下找同节点。 136. Single Number: A^0=A A^A=0 最后留下A
阅读全文
posted @
2016-10-10 06:55
Machelsky
阅读(85)
推荐(0)
125. Valid Palindrome
摘要:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example,"A man, a plan, a canal: Pan
阅读全文
posted @
2016-10-10 06:24
Machelsky
阅读(108)
推荐(0)
3. Longest Substring Without Repeating Characters
摘要:Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the leng
阅读全文
posted @
2016-10-10 06:02
Machelsky
阅读(114)
推荐(0)
387. First Unique Character in a String
摘要:Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. Examples:
阅读全文
posted @
2016-10-10 05:35
Machelsky
阅读(138)
推荐(0)
145. Binary Tree Postorder Traversal
摘要:Given a binary tree, return the postorder traversal of its nodes' values. For example:Given binary tree {1,#,2,3}, return [3,2,1]. 思路:后序遍历
阅读全文
posted @
2016-10-09 10:31
Machelsky
阅读(134)
推荐(0)
94. Binary Tree Inorder Traversal
摘要:Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary tree [1,null,2,3], return [1,3,2]. 思路:中序遍历。
阅读全文
posted @
2016-10-09 10:26
Machelsky
阅读(109)
推荐(0)
144. Binary Tree Preorder Traversal
摘要:Given a binary tree, return the preorder traversal of its nodes' values. For example:Given binary tree {1,#,2,3}, return [1,2,3]. Note: Recursive solu
阅读全文
posted @
2016-10-09 10:17
Machelsky
阅读(104)
推荐(0)
165. Compare Version Numbers
摘要:Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0. You may assum
阅读全文
posted @
2016-10-09 10:01
Machelsky
阅读(174)
推荐(0)
60. Permutation Sequence
摘要:The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order,We get the following sequence
阅读全文
posted @
2016-10-09 06:05
Machelsky
阅读(101)
推荐(0)
374. Guess Number Higher or Lower
摘要:We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to guess which number I picked. Every time you guess wron
阅读全文
posted @
2016-10-09 04:35
Machelsky
阅读(162)
推荐(0)
109. Convert Sorted List to Binary Search Tree
摘要:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. Given a singly linked list where element
阅读全文
posted @
2016-10-09 03:48
Machelsky
阅读(139)
推荐(0)
35. Search Insert Position
摘要:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in or
阅读全文
posted @
2016-10-09 03:36
Machelsky
阅读(121)
推荐(0)
16. 3Sum Closest
摘要:Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers.
阅读全文
posted @
2016-10-09 03:26
Machelsky
阅读(142)
推荐(0)
61. Rotate List
摘要:Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3-
阅读全文
posted @
2016-10-09 03:02
Machelsky
阅读(130)
推荐(0)
复习2
摘要:190. Reverse Bits:原数向右移动,如果bit是1,就给结果在相应的位置加上1. 46. Permutations:最适合这道题的dfs搜索顺序是把加一个限制条件:搜索过的数字跳过。脑子里面有个tree的模型然后去想应该搜索的顺序和条件。 100. Same Tree: 递归:检查是不
阅读全文
posted @
2016-10-09 02:34
Machelsky
阅读(84)
推荐(0)
89. Gray Code
摘要:The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total num
阅读全文
posted @
2016-10-09 02:25
Machelsky
阅读(140)
推荐(0)
204. Count Primes
摘要:Description: Count the number of prime numbers less than a non-negative number, n. 刷了一周的python, 希望明天把blackjack和最后的游戏做出来。 思路: 比较巧妙,用inner loop从头开始mark不
阅读全文
posted @
2016-10-08 17:14
Machelsky
阅读(94)
推荐(0)
复习1
摘要:1. Two sum: map解决,扫一遍记录位置为key,值为剩下值。 2. Add Two Numbers: 链表扫一遍, dummy node接算出来的node,跑完一个跑另一个,最后接上多出的node1 136. Single Number: 可以用map也可以用bit manipulati
阅读全文
posted @
2016-10-08 16:42
Machelsky
阅读(89)
推荐(0)
179. Largest Number
摘要:Given a list of non negative integers, arrange them such that they form the largest number. For example, given [3, 30, 34, 5, 9], the largest formed n
阅读全文
posted @
2016-10-08 15:23
Machelsky
阅读(108)
推荐(0)
147. Insertion Sort List
摘要:Sort a linked list using insertion sort. 思路:插入排序,就是把node插入到左边的链表中。用一个dummynode来构造左边的链表。要是比最左边的数还小,就插到最左边也就是dummy.next。如果不是,则linear search左边的链表插入。
阅读全文
posted @
2016-10-08 15:13
Machelsky
阅读(118)
推荐(0)
24. Swap Nodes in Pairs
摘要:Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2->3->4, you should return the list as 2->1->4->3. Your a
阅读全文
posted @
2016-10-08 14:39
Machelsky
阅读(117)
推荐(0)
79. Word Search
摘要:Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell, where "adjac
阅读全文
posted @
2016-10-08 14:26
Machelsky
阅读(174)
推荐(0)
69. Sqrt(x)
摘要:Implement int sqrt(int x). 二分法,找中值。注意不能用low<high来判断。举例:sqrt(5),low<high的话一直在2的右边搜索,最后low=3 high=3是不正确的,要再进入循环去得到最后的结果。
阅读全文
posted @
2016-10-08 14:04
Machelsky
阅读(124)
推荐(0)
334. Increasing Triplet Subsequence
摘要:Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array. Formally the function should: Your algorithm
阅读全文
posted @
2016-10-04 16:26
Machelsky
阅读(96)
推荐(0)
328. Odd Even Linked List
摘要:Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the
阅读全文
posted @
2016-10-04 16:00
Machelsky
阅读(126)
推荐(0)