Leetcode
leo524891010
坚持 耐心 高效
展开
-
[Leetcode] Symmetric Tree
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Soluti原创 2012-12-02 00:49:16 · 344 阅读 · 0 评论 -
[Leetcode] Climbing Stairs
class Solution {public: int climbStairs(int n) { // Start typing your C/C++ solution below // DO NOT write int main() function if (n == 1) return 1; el原创 2012-12-02 02:22:19 · 344 阅读 · 0 评论 -
[Leetcode] 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 Soluti原创 2012-12-02 03:43:49 · 323 阅读 · 0 评论 -
[Leetcode] Binary Tree Level Order Traversal II
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Soluti原创 2012-12-02 08:50:20 · 316 阅读 · 0 评论 -
[Leetcode] Convert Sorted Array to Binary Search Tree
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Soluti原创 2012-12-03 03:32:26 · 396 阅读 · 0 评论 -
[Leetcode] Palindrome Number
class Solution {public: bool isPalindrome(int x) { // Start typing your C/C++ solution below // DO NOT write int main() function if (x == 0) return true;原创 2012-12-03 08:48:35 · 578 阅读 · 0 评论 -
[Leetcode] First Missing Positive
class Solution {public: int firstMissingPositive(int A[], int n) { // Start typing your C/C++ solution below // DO NOT write int main() function if (n < 0) ret原创 2012-12-03 10:10:22 · 451 阅读 · 0 评论 -
[Leetcode] Best Time to Buy and Sell Stock
class Solution {public: int maxProfit(vector &a) { // Start typing your C/C++ solution below // DO NOT write int main() function int minIdx = 0; int diff = 0;原创 2012-12-01 09:26:25 · 496 阅读 · 0 评论 -
[Leetcode] Best Time to Buy and Sell Stock II
class Solution {public: int maxProfit(vector &a) { // Start typing your C/C++ solution below // DO NOT write int main() function int prevIdx = 0; int res原创 2012-12-01 09:58:46 · 703 阅读 · 0 评论 -
[Leetcode] Combination Sum II
class Solution {public: vector > combinationSum2(vector &candidates, int target) { // Start typing your C/C++ solution below // DO NOT write int main() function vector > r原创 2012-12-02 13:56:02 · 399 阅读 · 0 评论 -
[Leetcode] Combinations
class Solution {public: vector > combine(int n, int k) { // Start typing your C/C++ solution below // DO NOT write int main() function vector > res; vector cache;原创 2012-12-02 14:21:48 · 637 阅读 · 0 评论 -
[Leetcode] Same Tree
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Soluti原创 2012-12-03 04:54:46 · 364 阅读 · 0 评论 -
[Leetcode] Valid Parentheses
class Solution {public: bool isValid(string s) { // Start typing your C/C++ solution below // DO NOT write int main() function stack buf; for (int i = 0; i < s.siz原创 2012-12-03 05:07:53 · 435 阅读 · 0 评论 -
[Leetcode] Maximum Subarray
class Solution {public: int maxSubArray(int A[], int n) { // Start typing your C/C++ solution below // DO NOT write int main() function bool isAllNeg = true;原创 2012-12-03 07:22:22 · 568 阅读 · 0 评论 -
[Leetcode] Minimum Depth of Binary Tree
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Soluti原创 2012-12-03 08:07:17 · 493 阅读 · 0 评论 -
[Leetcode] Two Sum
class Solution {public: struct pair { int data; int idx; bool operator< (const pair& rhs) const { return data < rhs.data; } }; vec原创 2012-12-02 01:56:39 · 478 阅读 · 0 评论 -
[Leetcode] Best Time to Buy and Sell Stock III
class Solution {public: int maxProfit(vector &prices) { // Start typing your C/C++ solution below // DO NOT write int main() function if (a.size() == 0)原创 2012-12-01 12:04:01 · 652 阅读 · 0 评论 -
[Leetcode] Construct Binary Tree from Preorder and Inorder Traversal
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Soluti原创 2012-12-03 03:14:12 · 560 阅读 · 0 评论 -
[Leetcode] Convert Sorted List to Binary Search Tree
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; *//** * Definition for binary tree * stru原创 2012-12-03 04:07:35 · 351 阅读 · 0 评论 -
[Leetcode] Validate Binary Search Tree
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Soluti原创 2012-12-03 05:12:17 · 502 阅读 · 0 评论 -
[Leetcode] Maximum Depth of Binary Tree
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Soluti原创 2012-12-03 08:17:48 · 355 阅读 · 0 评论 -
[Leetcode] Add Binary
class Solution {public: string addBinary(string a, string b) { // Start typing your C/C++ solution below // DO NOT write int main() function string res; a.size() >原创 2012-12-02 02:59:26 · 345 阅读 · 0 评论 -
[Leetcode] 3Sum Closest
class Solution {public: int threeSumClosest(vector &num, int target) { // Start typing your C/C++ solution below // DO NOT write int main() function sort(num.begin(), num.原创 2012-12-01 13:56:04 · 528 阅读 · 0 评论 -
[Leetcode] Binary Tree Level Order Traversal
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Soluti原创 2012-12-02 08:11:25 · 384 阅读 · 0 评论 -
[Leetcode] Binary Tree Zigzag Level Order Traversal
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Soluti原创 2012-12-02 11:39:19 · 419 阅读 · 0 评论 -
[Leetcode] Combination Sum
class Solution {public: vector > combinationSum(vector &candidates, int target) { // Start typing your C/C++ solution below // DO NOT write int main() function vector > re原创 2012-12-02 13:27:51 · 400 阅读 · 0 评论 -
[Leetcode] Search a 2D Matrix
class Solution {public: bool searchMatrix(vector > &matrix, int target) { // Start typing your C/C++ solution below // DO NOT write int main() function int i = 0;原创 2012-12-03 04:25:52 · 471 阅读 · 0 评论 -
[Leetcode] Path Sum II
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Soluti原创 2012-12-03 09:10:22 · 443 阅读 · 0 评论 -
[Leetcode] Jump Game II
//大数据集 超时动态规划做法class Solution {public: int jump(int a[], int n) { // Start typing your C/C++ solution below // DO NOT write int main() function if (!n) return 0;原创 2012-12-04 03:46:54 · 458 阅读 · 0 评论 -
[Leetcode] Gray Code
class Solution {public: vector grayCode(int n) { // Start typing your C/C++ solution below // DO NOT write int main() function vector res; int total = 1 << n;原创 2012-12-04 08:14:00 · 465 阅读 · 0 评论 -
[Leetcode] Edit Distance
class Solution {public: int minDistance(string word1, string word2) { // Start typing your C/C++ solution below // DO NOT write int main() function int res = 0;原创 2012-12-03 23:58:43 · 605 阅读 · 0 评论 -
[Leetcode] Count and Say
class Solution {public: string countAndSay(int n) { // Start typing your C/C++ solution below // DO NOT write int main() function string s = "1"; for (int原创 2012-12-03 12:12:50 · 682 阅读 · 0 评论 -
[Leetcode] Distinct Subsequences *
class Solution {public: int numDistinct(string S, string T) { // Start typing your C/C++ solution below // DO NOT write int main() function int res = 0; match(S, T原创 2012-12-03 13:48:35 · 580 阅读 · 0 评论 -
[Leetcode] Length of Last Word
class Solution {public: int lengthOfLastWord(const char *s) { // Start typing your C/C++ solution below // DO NOT write int main() function int length = strlen(s);原创 2012-12-04 03:56:42 · 457 阅读 · 0 评论 -
[LeetCode] Divide Two Integers
class Solution {public: int divide(int dividend, int divisor) { // Start typing your C/C++ solution below // DO NOT write int main() function long long a = dividend;原创 2012-12-03 23:40:27 · 607 阅读 · 0 评论 -
[Leetcode] Generate Parentheses
class Solution {public: vector generateParenthesis(int n) { // Start typing your C/C++ solution below // DO NOT write int main() function vector res; string s = ""原创 2012-12-04 04:05:41 · 527 阅读 · 0 评论 -
[Leetcode] Word Search
class Solution {public: bool exist(vector > &board, string word) { // Start typing your C/C++ solution below // DO NOT write int main() function vector used;原创 2012-12-04 09:49:20 · 726 阅读 · 0 评论 -
[Leetcode] Pascal's Triangle
class Solution {public: vector > generate(int numRows) { // Start typing your C/C++ solution below // DO NOT write int main() function vector > res;原创 2012-12-04 14:04:19 · 650 阅读 · 0 评论 -
[Leetcode] Largest Rectangle in Histogram
class Solution {public: int largestRectangleArea(vector &height) { // Start typing your C/C++ solution below // DO NOT write int main() function int q[100000] = {-1};原创 2012-12-04 23:49:43 · 489 阅读 · 0 评论 -
[Leetcode] Letter Combinations of a Phone Number
class Solution {private: map > dict;public: vector letterCombinations(string digits) { // Start typing your C/C++ solution below // DO NOT write int main() function原创 2012-12-05 03:52:49 · 544 阅读 · 0 评论