2013年10月16日

Combination Sum

摘要: Given a set of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Thesamerepeated number may be chosen fromCunlimited number of times.Note:All numbers (including target) will be positive integers.Elements in a combination (a1,a2, … ,ak 阅读全文

posted @ 2013-10-16 21:58 waruzhi 阅读(193) 评论(0) 推荐(0) 编辑

Pow(x, n)

摘要: Implement pow(x,n).思路二分,然后注意特殊情况的判断。最开始提交好几次都不成功。超时是因为使用递归的时候算了两次,应该用一个变量把值存起来然后直接使用的。WA是因为忘记了负数模2可能得到-1的情况。 1 double pow(double x, int n) { 2 // Note: The Solution object is instantiated only once and is reused by each test case. 3 if(x == 0 || x == 1) 4 return x; 5 ... 阅读全文

posted @ 2013-10-16 21:06 waruzhi 阅读(448) 评论(0) 推荐(0) 编辑

Validate Binary Search Tree

摘要: Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keysless thanthe node's key.The right subtree of a node contains only nodes with keysgreater thanthe node's key.Both the left and ri 阅读全文

posted @ 2013-10-16 20:23 waruzhi 阅读(156) 评论(0) 推荐(0) 编辑

导航