2013年12月15日
摘要: Anagrams2013.12.15 22:00Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.Solution: Anagrams means that strings composed of the same group of letters, such as [ate, eat, tea]. They'll become the same when sorted: aet. My solution is 阅读全文
posted @ 2013-12-15 22:19 zhuli19901106 阅读(211) 评论(0) 推荐(0)
摘要: Rotate Image2013.12.15 21:40You are given annxn2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?Solution: Rotate an nXn 2D matrix in-place. See the picture below and that's how I did the rotation: ABCDA DEFEB CFXFC BEFED ... 阅读全文
posted @ 2013-12-15 21:42 zhuli19901106 阅读(287) 评论(0) 推荐(0)
摘要: Permutations II2013.12.15 05:30Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2]have the following unique permutations:[1,1,2],[1,2,1], and[2,1,1].Solution: This time the array may contain duplicates, so I implemented the next_p. 阅读全文
posted @ 2013-12-15 05:39 zhuli19901106 阅读(499) 评论(0) 推荐(0)
摘要: Permutations2013.12.15 05:08Given a collection of numbers, return all possible permutations.For example,[1,2,3]have the following permutations:[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2], and[3,2,1].Solution: The STL library provides a function next_permutation(), which generates the next greater perm.. 阅读全文
posted @ 2013-12-15 05:10 zhuli19901106 阅读(200) 评论(0) 推荐(0)
摘要: Multiply Strings2013.12.15 04:07Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.Solution: I just did a digit-by-digit multiplication. There seemed to be a very complicated O(n * log(n)) soluti. 阅读全文
posted @ 2013-12-15 04:23 zhuli19901106 阅读(286) 评论(0) 推荐(0)
摘要: Combination Sum II2013.12.15 03:51Given a collection of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Each number inCmay only be usedoncein the combination.Note:All numbers (including target) will be positive integers.Elements in 阅读全文
posted @ 2013-12-15 04:05 zhuli19901106 阅读(540) 评论(0) 推荐(0)
摘要: Combination Sum2013.12.15 03:10Given a set of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Thesamerepeated number may be chosen fromCunlimited number of times.Note:All numbers (including target) will be positive integers.Elements 阅读全文
posted @ 2013-12-15 03:44 zhuli19901106 阅读(1392) 评论(0) 推荐(0)
摘要: Count and Say2013.12.15 03:00The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1is read off as"one 1"or11.11is read off as"two 1s"or21.21is read off as"one 2, thenone 1"or1211.Given an integern, generate thenthsequen 阅读全文
posted @ 2013-12-15 03:10 zhuli19901106 阅读(732) 评论(0) 推荐(0)
摘要: Valid Sudoku2013.12.15 02:59Determine if a Sudoku is valid, according to:Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character'.'.A partially filled sudoku which is valid.Solution: For introduction of Sudoku game, please see Su 阅读全文
posted @ 2013-12-15 03:00 zhuli19901106 阅读(230) 评论(0) 推荐(0)
摘要: Search Insert Position2013.12.15 00:03Given 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 order.You may assume no duplicates in the array.Here are few examples.[1,3,5,6], 5 → 2[1,3,5,6], 2 → 1[1,3,5,6], 7 阅读全文
posted @ 2013-12-15 00:54 zhuli19901106 阅读(250) 评论(0) 推荐(0)