随笔分类 -  Leetcode

摘要:Given a strings, partitionssuch that every substring of the partition is a palindrome.Return all possible palindrome partitioning ofs.For example, giv... 阅读全文
posted @ 2015-09-01 22:41 胡潇 阅读(805) 评论(0) 推荐(0)
摘要:A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message conta... 阅读全文
posted @ 2015-09-01 17:15 胡潇 阅读(596) 评论(0) 推荐(0)
摘要: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 "adjace... 阅读全文
posted @ 2015-09-01 15:33 胡潇 阅读(817) 评论(0) 推荐(0)
摘要:Given amxnmatrix, if an element is 0, set its entire row and column to 0. Do it in place.解题思路:题目乍一看很简单,将矩阵当前为0的位的行列都置为0;问题在于:当遇到一个已知0时,不能立刻将其行列置0,因为这样... 阅读全文
posted @ 2015-09-01 14:59 胡潇 阅读(522) 评论(0) 推荐(0)
摘要:Validate if a given string is numeric.Some examples:"0"=>true" 0.1 "=>true"abc"=>false"1 a"=>false"2e10"=>trueNote:It is intended for the problem stat... 阅读全文
posted @ 2015-08-31 22:39 胡潇 阅读(615) 评论(0) 推荐(0)
摘要:Given a set ofnon-overlappingintervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially... 阅读全文
posted @ 2015-08-31 22:23 胡潇 阅读(655) 评论(0) 推荐(0)
摘要:Given a collection of intervals, merge all overlapping intervals.For example,Given[1,3],[2,6],[8,10],[15,18],return[1,6],[8,10],[15,18].解题思路:1、将区间按照起始... 阅读全文
posted @ 2015-08-31 10:40 胡潇 阅读(609) 评论(0) 推荐(0)
摘要:Implement pow(x,n).解题思路:求浮点数的幂次方,注意可能为负数次幂;可以使用二分搜索的思想,当n为偶数时,x^n = x^(n/2) * x^(n/2),因此只需要求得一半的幂次方,将结果平方,就得到所求结果。解题步骤:1、递归最底层,n == 0 时,返回1;2、求出t = po... 阅读全文
posted @ 2015-08-30 16:11 胡潇 阅读(514) 评论(0) 推荐(0)
摘要:Given an array of strings, group anagrams together.For example, given:["eat", "tea", "tan", "ate", "nat", "bat"],Return:[ ["ate", "eat","tea"], ["na... 阅读全文
posted @ 2015-08-30 15:43 胡潇 阅读(642) 评论(0) 推荐(0)
摘要:Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.解题思路:1、先取出k个list的首元素,每个首元素是对应list中的最小元素,组成一个具有k个结点的最小堆... 阅读全文
posted @ 2015-08-28 12:05 胡潇 阅读(944) 评论(0) 推荐(0)
摘要:Compare two version numbersversion1andversion2.Ifversion1>version2return 1, ifversion1 num2) 22 return 1;23 else if (num1 ... 阅读全文
posted @ 2015-08-26 09:48 胡潇 阅读(1171) 评论(0) 推荐(0)
摘要:Given a binary tree, return thepostordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[3,2,1].解题... 阅读全文
posted @ 2015-06-30 04:29 胡潇 阅读(311) 评论(0) 推荐(0)
摘要:Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the arr... 阅读全文
posted @ 2015-06-29 04:15 胡潇 阅读(263) 评论(0) 推荐(0)
摘要:Given two stringssandt, determine if they are isomorphic.Two strings are isomorphic if the characters inscan be replaced to gett.All occurrences of a ... 阅读全文
posted @ 2015-06-27 21:18 胡潇 阅读(183) 评论(0) 推荐(0)
摘要:Given an absolute path for a file (Unix-style), simplify it.For example,path="/home/", =>"/home"path="/a/./b/../../c/", =>"/c"Corner Cases:Did you con... 阅读全文
posted @ 2015-06-25 10:30 胡潇 阅读(221) 评论(0) 推荐(0)
摘要:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single ... 阅读全文
posted @ 2015-06-24 02:59 胡潇 阅读(283) 评论(0) 推荐(0)
摘要:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy ... 阅读全文
posted @ 2015-06-23 03:40 胡潇 阅读(269) 评论(0) 推荐(0)
摘要:Given 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 multiple ofkthen left-o... 阅读全文
posted @ 2015-06-22 03:43 胡潇 阅读(212) 评论(0) 推荐(0)
摘要:Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.解题:寻找单链表中环的入口,如果不存在环则返回null。假设单链表有环,先利用判断单链表是否有环(Linked ... 阅读全文
posted @ 2015-06-21 04:01 胡潇 阅读(205) 评论(0) 推荐(0)
摘要:Given a linked list, determine if it has a cycle in it.解题:判断单链表是否具有环,使用两个指针once和twice遍历链表,once一次走一步,twice一次走两步,如果相遇,则说明有环,否则没有。原因是,如果单链表具有环,不论once和twi... 阅读全文
posted @ 2015-06-20 04:04 胡潇 阅读(221) 评论(0) 推荐(0)