随笔分类 -  leetcode

摘要:The string"PAYPALISHIRING"is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font fo... 阅读全文
posted @ 2014-10-31 23:16 birdhack 阅读(178) 评论(0) 推荐(0)
摘要:Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened t... 阅读全文
posted @ 2014-10-30 23:34 birdhack 阅读(147) 评论(0) 推荐(0)
摘要:Write a function to find the longest common prefix string amongst an array of strings.找出所有字符串的最长公共前缀。 1 public class Solution { 2 public String lo... 阅读全文
posted @ 2014-10-30 18:35 birdhack 阅读(123) 评论(0) 推荐(0)
摘要:Givennnon-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.Fo... 阅读全文
posted @ 2014-10-30 00:35 birdhack 阅读(129) 评论(0) 推荐(0)
摘要:Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100". 1 public class Solution { 2 public String ... 阅读全文
posted @ 2014-10-28 23:10 birdhack 阅读(98) 评论(0) 推荐(0)
摘要:Given a set of distinct integers,S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not co... 阅读全文
posted @ 2014-10-27 23:23 birdhack 阅读(141) 评论(0) 推荐(0)
摘要:Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (i... 阅读全文
posted @ 2014-10-27 18:31 birdhack 阅读(90) 评论(0) 推荐(0)
摘要:The 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"tw... 阅读全文
posted @ 2014-10-25 15:18 birdhack 阅读(113) 评论(0) 推荐(0)
摘要:Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets must close in the correct ... 阅读全文
posted @ 2014-10-25 13:04 birdhack 阅读(96) 评论(0) 推荐(0)
摘要:Given a stringsconsists of upper/lower-case alphabets and empty space characters' ', return the length of last word in the string.If the last word doe... 阅读全文
posted @ 2014-10-24 12:08 birdhack 阅读(88) 评论(0) 推荐(0)
摘要:Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest le... 阅读全文
posted @ 2014-10-24 11:57 birdhack 阅读(120) 评论(0) 推荐(0)
摘要:Given a linked list, remove thenthnode from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After re... 阅读全文
posted @ 2014-10-24 11:46 birdhack 阅读(119) 评论(0) 推荐(0)
摘要:Given two integersnandk, return all possible combinations ofknumbers out of 1 ...n.For example,Ifn= 4 andk= 2, a solution is:[ [2,4], [3,4], [2,3],... 阅读全文
posted @ 2014-10-24 10:49 birdhack 阅读(95) 评论(0) 推荐(0)
摘要:Implement strStr().Returns a pointer to the first occurrence of needle in haystack, ornullif needle is not part of haystack. 1 public class Solution {... 阅读全文
posted @ 2014-10-22 23:50 birdhack 阅读(167) 评论(0) 推荐(0)
摘要:Given an indexk, return thekthrow of the Pascal's triangle.For example, givenk= 3,Return[1,3,3,1].Note:Could you optimize your algorithm to use onlyO(... 阅读全文
posted @ 2014-10-21 18:00 birdhack 阅读(135) 评论(0) 推荐(0)
摘要:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.Fo... 阅读全文
posted @ 2014-10-20 22:25 birdhack 阅读(102) 评论(0) 推荐(0)
摘要:Given a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For exa... 阅读全文
posted @ 2014-10-20 22:13 birdhack 阅读(131) 评论(0) 推荐(0)
摘要:Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete a... 阅读全文
posted @ 2014-10-19 21:34 birdhack 阅读(121) 评论(0) 推荐(0)
摘要:Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree{3,9,2... 阅读全文
posted @ 2014-10-19 00:00 birdhack 阅读(129) 评论(0) 推荐(0)
摘要:Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie... 阅读全文
posted @ 2014-10-18 21:11 birdhack 阅读(104) 评论(0) 推荐(0)