Tony's Log

Algorithms, Distributed System, Machine Learning

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

2014年7月21日

摘要: DFS and using stack to validate candidates.class Solution {public: bool isValid(const string &s) { stack stk; for (int i = 0; i &... 阅读全文
posted @ 2014-07-21 11:02 Tonix 阅读(144) 评论(0) 推荐(0)

摘要: The trick is, we can work on a reversed vector - learnt from EPI.class Solution {public: vector plusOne(vector &digits) { std::reverse(digit... 阅读全文
posted @ 2014-07-21 10:32 Tonix 阅读(147) 评论(0) 推荐(0)

摘要: Recursive.class Solution { public: bool isSymmetric(TreeNode *pl, TreeNode *pr) { if (!pl && !pr) return true; if ((pl && !pr)... 阅读全文
posted @ 2014-07-21 10:19 Tonix 阅读(146) 评论(0) 推荐(0)

摘要: My first reaction: move all A elements back by n positions, and start everything from A[0] and B[0]. But a smarter idea is to start everything from th... 阅读全文
posted @ 2014-07-21 10:18 Tonix 阅读(131) 评论(0) 推荐(0)

摘要: Another recursion problem.class Solution {public: int getHeight(TreeNode *p) { if (!p) return 0; int hL = 1; if (p->left) h... 阅读全文
posted @ 2014-07-21 07:38 Tonix 阅读(170) 评论(0) 推荐(0)

摘要: Classic recursion\pruning problem. We can use O(n) space: A[i] = j means [i,j] is occupied.class Solution {public: int ret; bool isValid(int *A,... 阅读全文
posted @ 2014-07-21 06:49 Tonix 阅读(125) 评论(0) 推荐(0)

摘要: Simply care about the boundary cases:class Solution {public: ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) { if (l1 && !l2) return l1;... 阅读全文
posted @ 2014-07-21 05:53 Tonix 阅读(166) 评论(0) 推荐(0)

摘要: Apparently BFS is the most obvious one.. but it is not that simple - only constant extra space is provided.Then the only strategy to take is recursion... 阅读全文
posted @ 2014-07-21 04:39 Tonix 阅读(270) 评论(0) 推荐(0)

摘要: Very classic problem. You can brush up your DP and Searching skills.DP:class Solution {public: int maxSubArray(int A[], int n) { // dp[i + 1... 阅读全文
posted @ 2014-07-21 04:19 Tonix 阅读(189) 评论(0) 推荐(0)