上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 17 下一页
摘要: Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For example,Given n = 3, your program should return all 5 unique BST's shown below. 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / ... 阅读全文
posted @ 2013-10-04 12:16 懒猫欣 阅读(193) 评论(0) 推荐(0)
摘要: Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ \ 2 ... 阅读全文
posted @ 2013-10-04 03:03 懒猫欣 阅读(165) 评论(0) 推荐(0)
摘要: Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:a) Insert a characterb) Delete a characterc) Replace a characterclass Solution {public: int minDistan... 阅读全文
posted @ 2013-10-04 02:05 懒猫欣 阅读(143) 评论(0) 推荐(0)
摘要: Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−1,2,1] has the largest sum = 6.click to show more practice.More practice:If you have figured out the O(n) solution 阅读全文
posted @ 2013-10-04 00:39 懒猫欣 阅读(123) 评论(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 {public: void sub(string &s,string&ret,i 阅读全文
posted @ 2013-10-04 00:28 懒猫欣 阅读(185) 评论(0) 推荐(0)
摘要: Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree. For example:Given the below binary tree, 1 / \ 2 3Return 6./** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNo... 阅读全文
posted @ 2013-10-03 23:38 懒猫欣 阅读(142) 评论(0) 推荐(0)
摘要: Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree./** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NU... 阅读全文
posted @ 2013-10-03 22:54 懒猫欣 阅读(159) 评论(0) 推荐(0)
摘要: Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree./** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(N... 阅读全文
posted @ 2013-10-03 21:46 懒猫欣 阅读(191) 评论(0) 推荐(0)
摘要: Given an array of integers, every element appears three times except for one. Find that single one. Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?class Solution {public: void toTribit(vector& bits,int val){ if(val0){... 阅读全文
posted @ 2013-10-03 21:27 懒猫欣 阅读(405) 评论(0) 推荐(0)
摘要: There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its next station (i+1). You begin the journey with an empty tank at one of the gas stations.Return the sta 阅读全文
posted @ 2013-10-03 16:58 懒猫欣 阅读(214) 评论(0) 推荐(0)
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 17 下一页