上一页 1 2 3 4 5 6 7 ··· 34 下一页
摘要: Given two words (startandend), and a dictionary, find the length of shortest transformation sequence fromstarttoend, such that:Only one letter can be changed at a timeEach intermediate word must exist in the dictionaryFor example,Given:start="hit"end="cog"dict=["hot",&q 阅读全文
posted @ 2014-03-13 13:33 七年之后 阅读(223) 评论(0) 推荐(0) 编辑
摘要: 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.思考:空间换时间,查找O(1)用unordered_set。class Sol 阅读全文
posted @ 2014-03-13 09:56 七年之后 阅读(201) 评论(0) 推荐(0) 编辑
摘要: Given a strings, partitionssuch that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning ofs.For example, givens="aab",Return1since the palindrome partitioning["aa","b"]could be produced using 1 cut.class Solutio 阅读全文
posted @ 2014-03-12 22:10 七年之后 阅读(149) 评论(0) 推荐(0) 编辑
摘要: Given a strings, partitionssuch that every substring of the partition is a palindrome.Return all possible palindrome partitioning ofs.For example, givens="aab",Return [ ["aa","b"], ["a","a","b"] ]class Solution {private: vector > res;pub 阅读全文
posted @ 2014-03-12 21:27 七年之后 阅读(127) 评论(0) 推荐(0) 编辑
摘要: Given a stringsand a dictionary of wordsdict, add spaces insto construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, givens="catsanddog",dict=["cat", "cats", "and", "sand", "dog"].A 阅读全文
posted @ 2014-03-12 20:36 七年之后 阅读(162) 评论(0) 推荐(0) 编辑
摘要: Givenn, generate all structurally uniqueBST's(binary search trees) that store values 1...n.For example,Givenn= 3, your program should return all 5 unique BST's shown below. 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ ... 阅读全文
posted @ 2014-03-12 20:26 七年之后 阅读(157) 评论(0) 推荐(0) 编辑
摘要: Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given"25525511135",return["255.255.11.135", "255.255.111.35"]. (Order does not matter)class Solution {private: vector ret; int pos[4];public: bool check 阅读全文
posted @ 2014-03-12 12:24 七年之后 阅读(176) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1 \ 2 \ 3 \ 4 \ 5 \ 6click to show hints.Hints:If y... 阅读全文
posted @ 2014-03-12 11:25 七年之后 阅读(222) 评论(0) 推荐(0) 编辑
摘要: Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; *//** * Definition for binary tree * struc... 阅读全文
posted @ 2014-03-12 10:22 七年之后 阅读(173) 评论(0) 推荐(0) 编辑
摘要: Given an array where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: ... 阅读全文
posted @ 2014-03-11 22:41 七年之后 阅读(125) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 ··· 34 下一页