摘要: C++ 1 class Solution { 2 public: 3 /** 4 * @param x: An integer 5 * @return: The sqrt of x 6 */ 7 int sqrt(int x) { 8 /... 阅读全文
posted @ 2015-11-30 13:03 ZH奶酪 阅读(295) 评论(0) 推荐(0) 编辑
摘要: C++逆推 1 class Solution { 2 public: 3 /** 4 * @param triangle: a list of lists of integers. 5 * @return: An integer, minimum path sum. 6 ... 阅读全文
posted @ 2015-11-30 12:35 ZH奶酪 阅读(271) 评论(0) 推荐(0) 编辑
摘要: C++双向递推空间O(1)时间O(n) 1 class Solution { 2 public: 3 /** 4 * @param A an array of Integer 5 * @return an integer 6 */ 7 int long... 阅读全文
posted @ 2015-11-30 12:08 ZH奶酪 阅读(188) 评论(0) 推荐(0) 编辑
摘要: C++Divide-Conquer[71% passed] 1 class Solution { 2 public: 3 /** 4 * @param nums: a list of integers 5 * @return: A integer denote the s... 阅读全文
posted @ 2015-11-30 11:50 ZH奶酪 阅读(198) 评论(0) 推荐(0) 编辑
摘要: C++dp递推式:dp[i][j] = dp[i-1][j] + dp[i][j-1]初值:dp[i][j] = 1,i=0 or j=0空间优化:省掉一维 1 class Solution { 2 public: 3 /** 4 * @param n, m: positive i... 阅读全文
posted @ 2015-11-30 11:31 ZH奶酪 阅读(241) 评论(0) 推荐(0) 编辑
摘要: C++ 1 class Solution { 2 public: 3 /** 4 *@param a, b: Two integer 5 *return: An integer 6 */ 7 int bitSwapRequired(int a, int ... 阅读全文
posted @ 2015-11-30 11:13 ZH奶酪 阅读(192) 评论(0) 推荐(0) 编辑
摘要: dp注意问题 递推式 初值 空间优化1. bfs题目里有“最小”字样,符合bfs关键词:上界len(S)+len(T)实际上不可行;2. dp删除字符很麻烦换个角度,变为字符串“对齐问题”:S = ABCFT = DBFGS:A B C F -T:D B - F G对应位置相同则不扣分,不同则... 阅读全文
posted @ 2015-11-30 10:59 ZH奶酪 阅读(292) 评论(0) 推荐(0) 编辑
摘要: 1. 暴力枚举2. “聪明”枚举3. 分治法分:两个基本等长的子数组,分别求解T(n/2)合:跨中心点的最大子数组合(枚举)O(n)时间复杂度:O(n*logn) 1 class Solution { 2 public: 3 /** 4 * @param nums: A l... 阅读全文
posted @ 2015-11-30 10:22 ZH奶酪 阅读(249) 评论(0) 推荐(0) 编辑