qingcheng奕  
10 2013 档案
  • LeetCode OJ——Two Sum
    摘要:http://oj.leetcode.com/problems/two-sum/求是否存在两个数的和为target,暴力法,两层循环#include #include #include using namespace std;class Solution {public: vector twoSum(vector &numbers, int target) { // Note: The Solution object is instantiated only once and is reused by each test case. //sort(number... 阅读全文
    posted @ 2013-10-26 11:46 qingcheng奕 阅读(185) 评论(0) 推荐(0)
  • LeetCode OJ——Longest Valid Parentheses
    摘要:http://oj.leetcode.com/problems/longest-valid-parentheses/最大括号匹配长度,括号是可以嵌套的#include #include #include #include using namespace std;class Solution {public: int longestValidParentheses(string s) { const int s_len = s.size(); stack indexstack; vector flagvector; int templ... 阅读全文
    posted @ 2013-10-26 10:51 qingcheng奕 阅读(135) 评论(0) 推荐(0)
  • LeetCode OJ——Longest Valid Parentheses
    摘要:http://oj.leetcode.com/problems/longest-valid-parentheses/最大括号匹配长度,括号是可以嵌套的。 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 class Solution { 7 public: 8 int longestValidParentheses(string s) { 9 const int s_len = s.size();10 11 stack indexstack;12 ... 阅读全文
    posted @ 2013-10-26 10:49 qingcheng奕 阅读(129) 评论(0) 推荐(0)
  • LeetCode OJ——Binary Tree Inorder Traversal
    摘要:http://oj.leetcode.com/problems/binary-tree-inorder-traversal/树的中序遍历,递归方法,和非递归方法。/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {private: void subfunc... 阅读全文
    posted @ 2013-10-23 20:49 qingcheng奕 阅读(209) 评论(0) 推荐(0)
  • LeetCode OJ——Validate Binary Search Tree
    摘要:http://oj.leetcode.com/problems/validate-binary-search-tree/判断一棵树是否为二叉搜索树。key 是,在左子树往下搜索的时候,要判断是不是子树的值都小于跟的值,在右子树往下搜索的时候,要判断,是不是都大于跟的值。很好的一个递归改进算法。简洁有思想! 1 #include 2 3 // Definition for binary tree 4 struct TreeNode { 5 int val; 6 TreeNode *left; 7 TreeNode *right; 8 Tre... 阅读全文
    posted @ 2013-10-22 21:17 qingcheng奕 阅读(202) 评论(0) 推荐(0)
  • LeetCode OJ——Subsets
    摘要:http://oj.leetcode.com/problems/subsets/计算一个集合的子集,使用vector >,使用了进制的思想。#include#include#include#includeusing namespace std;class Solution {private: void myoutput(vector &input) { for(int i=0;i > subsets(vector &S) { // Note: The Solution object is instantiated only once and is reused by 阅读全文
    posted @ 2013-10-19 15:02 qingcheng奕 阅读(248) 评论(1) 推荐(0)