随笔分类 -  leetcode

摘要:Divide Two IntegersDivide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.思路:类似二分查找算法,只不过我们做的是对... 阅读全文
posted @ 2015-04-02 11:32 imKirin 阅读(155) 评论(0) 推荐(0)
摘要:N-Queens IIFollow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions. 1 class Solutio... 阅读全文
posted @ 2015-03-30 15:02 imKirin 阅读(116) 评论(0) 推荐(0)
摘要:N-QueensThen-queens puzzle is the problem of placingnqueens on ann×nchessboard such that no two queens attack each other.Given an integern, return all... 阅读全文
posted @ 2015-03-30 14:24 imKirin 阅读(152) 评论(0) 推荐(0)
摘要:Minimum Path SumGiven amxngrid filled with non-negative numbers, find a path from top left to bottom right whichminimizesthe sum of all numbers along ... 阅读全文
posted @ 2015-03-27 10:32 imKirin 阅读(182) 评论(0) 推荐(0)
摘要:Longest Valid ParenthesesGiven a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substr... 阅读全文
posted @ 2015-03-20 15:22 imKirin 阅读(141) 评论(0) 推荐(0)
摘要:Reverse Nodes in k-GroupGiven a linked list, reverse the nodes of a linked listkat a time and return its modified list.If the number of nodes is not a... 阅读全文
posted @ 2015-03-19 14:48 imKirin 阅读(143) 评论(0) 推荐(0)
摘要:CombinationsGiven two integersnandk, return all possible combinations ofknumbers out of 1 ...n.For example,Ifn= 4 andk= 2, a solution is:[ [2,4], [3... 阅读全文
posted @ 2015-03-17 17:29 imKirin 阅读(155) 评论(0) 推荐(0)
摘要:Search for a RangeGiven a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity ... 阅读全文
posted @ 2015-03-17 15:30 imKirin 阅读(153) 评论(0) 推荐(0)
摘要:Combination Sum IIGiven a collection of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sum... 阅读全文
posted @ 2015-03-16 12:22 imKirin 阅读(153) 评论(0) 推荐(0)
摘要:Combination SumGiven a set of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Thes... 阅读全文
posted @ 2015-03-16 10:36 imKirin 阅读(152) 评论(0) 推荐(0)
摘要:Reverse BitsReverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as000000101001010000011110100111... 阅读全文
posted @ 2015-03-10 13:50 imKirin 阅读(113) 评论(0) 推荐(0)
摘要:Number of 1 BitsWrite a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as theHamming weight).For exampl... 阅读全文
posted @ 2015-03-10 11:25 imKirin 阅读(108) 评论(0) 推荐(0)
摘要:Longest Substring Without Repeating CharactersGiven a string, find the length of the longest substring without repeating characters. For example, the ... 阅读全文
posted @ 2015-03-05 15:59 imKirin 阅读(155) 评论(0) 推荐(0)
摘要:Reverse Words in a StringGiven an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".Updat... 阅读全文
posted @ 2015-03-05 13:54 imKirin 阅读(141) 评论(0) 推荐(0)
摘要:Rotate ArrayRotate an array ofnelements to the right byksteps.For example, withn= 7 andk= 3, the array[1,2,3,4,5,6,7]is rotated to[5,6,7,1,2,3,4].Note... 阅读全文
posted @ 2015-03-04 16:45 imKirin 阅读(160) 评论(0) 推荐(0)
摘要:Letter Combinations of a Phone NumberGiven a digit string, return all possible letter combinations that the number could represent.A mapping of digit ... 阅读全文
posted @ 2015-03-04 14:20 imKirin 阅读(161) 评论(0) 推荐(0)
摘要:Search Insert PositionGiven 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 ... 阅读全文
posted @ 2015-02-03 21:53 imKirin 阅读(123) 评论(0) 推荐(0)
摘要:Swap Nodes in PairsGiven a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2-... 阅读全文
posted @ 2015-02-03 18:16 imKirin 阅读(128) 评论(0) 推荐(0)
摘要:Multiply StringsGiven two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large ... 阅读全文
posted @ 2015-02-03 14:50 imKirin 阅读(134) 评论(0) 推荐(0)
摘要:Permutation SequenceThe set[1,2,3,…,n]contains a total ofn! unique permutations.By listing and labeling all of the permutations in order,We get the fo... 阅读全文
posted @ 2015-02-02 14:26 imKirin 阅读(128) 评论(0) 推荐(0)