随笔分类 - leecode
leecode上面的一些算法题目。
摘要:Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given[100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is[1, 2, 3, 4]. Return its length:4.Your algorithm should run in O(n) complexity.这道题貌似在陈利人的微博上看到过,当时是有思路的:即采用hash的方法。但是再
阅读全文
摘要:Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the total sum of all root-to-leaf numbers.For example, 1 / \ 2 3The root-to-leaf path 1->2 represents the num
阅读全文
摘要:Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region .For example,X X X XX O O XX X O XX O X XAfter running your function, the board should be:X X X XX X X
阅读全文
摘要:Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab", Return [ ["aa","b"], ["a","a","b"] ]不太清楚。网上说是用dfs来做,但是可能因为自己水平不够,不明白如何算是
阅读全文

浙公网安备 33010602011771号