![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
文章平均质量分 56
呼呼猪
这个作者很懒,什么都没留下…
展开
-
【leetcode】Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330. Note: The result may be ve原创 2015-02-01 20:18:16 · 846 阅读 · 0 评论 -
[leetcode]Merge Intervals
先写了一个O(n^2)的算法 /** * Definition for an interval. * struct Interval { * int start; * int end; * Interval() : start(0), end(0) {} * Interval(int s, int e) : start(s), end(e) {} *原创 2013-07-30 13:31:20 · 766 阅读 · 0 评论 -
[leetcode]Insert Interval
/** * Definition for an interval. * struct Interval { * int start; * int end; * Interval() : start(0), end(0) {} * Interval(int s, int e) : start(s), end(e) {} * }; */ class So原创 2013-07-30 13:07:20 · 637 阅读 · 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 M = word1.原创 2013-07-23 23:04:22 · 632 阅读 · 0 评论 -
[leetcode]Minimum Window Substring
我只想说这个题目被我写成了一坨翔。。。。 需要重写。。。mark class Solution { public: bool containsT(vector &S, vector &T){ for(int i = 0; i < 256; i++){ if(S[i] < T[i]) return false; }原创 2013-07-23 11:38:05 · 735 阅读 · 0 评论 -
[leetcode]jump game
class Solution { public: bool canJump(int A[], int n) { // Start typing your C/C++ solution below // DO NOT write int main() function if(n == 0) return false; if(n原创 2013-07-30 14:07:43 · 583 阅读 · 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 N = 0; const char *原创 2013-07-29 22:43:48 · 599 阅读 · 0 评论 -
[leetcode]Combinations
class Solution { vector> result; public: void dfs(vector &tmp, int level, int n, int k){ if(level > n){ if(tmp.size() == k){ result.push_back(tmp);原创 2013-07-22 14:02:50 · 595 阅读 · 0 评论 -
[leetcode]Remove Duplicates from Sorted List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *de原创 2013-07-20 17:49:05 · 557 阅读 · 0 评论 -
[leetcode]Partition List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *pa原创 2013-07-20 15:36:20 · 654 阅读 · 0 评论 -
[leetcode]Remove Duplicates from Sorted Array II
class Solution { public: int removeDuplicates(int A[], int n) { // Start typing your C/C++ solution below // DO NOT write int main() function int len = 0; int time原创 2013-07-21 08:47:37 · 653 阅读 · 0 评论 -
[leetcode]Remove Duplicates from Sorted List II
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *de原创 2013-07-20 20:43:30 · 506 阅读 · 0 评论 -
[leetcode]Maximal Rectangle
class Solution { public: int largestRectangleArea(vector &height) { // Start typing your C/C++ solution below // DO NOT write int main() function if(height.empty()) return原创 2013-07-20 17:21:32 · 593 阅读 · 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 if(height.empty()) return原创 2013-07-20 16:20:24 · 575 阅读 · 0 评论 -
[leetcode]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 keys less than the node's key.原创 2013-07-05 10:36:40 · 559 阅读 · 0 评论 -
[leetcode]Remove Duplicates from Sorted Array
class Solution { public: int removeDuplicates(int A[], int n) { // Start typing your C/C++ solution below // DO NOT write int main() function int len = 0; for(int i原创 2013-07-21 08:23:41 · 840 阅读 · 1 评论 -
[leetcode]in Rotated Sorted Array
class Solution { public: int search(int A[], int n, int target) { // Start typing your C/C++ solution below // DO NOT write int main() function int start = 0; int e原创 2013-07-20 21:41:28 · 480 阅读 · 0 评论 -
[leetcode]Scramble String
3D dp问题 class Solution { public: bool isScramble(string s1, string s2) { // Start typing your C/C++ solution below // DO NOT write int main() function int N = s1.size();原创 2013-07-20 14:40:17 · 682 阅读 · 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 if(matrix.empty())原创 2013-07-23 19:36:28 · 507 阅读 · 0 评论 -
[leetcode]Set Matrix Zeroes
class Solution { public: void setRow(vector > &matrix, int i){ for(int j = 0; j < matrix[0].size(); j++){ matrix[i][j] = 0; } } void setCol(vector > &matri原创 2013-07-23 22:14:46 · 676 阅读 · 0 评论 -
[leetcode]Sort Colors
class Solution { public: void sortColors(int A[], int n) { // Start typing your C/C++ solution below // DO NOT write int main() function int n1 = 0, n2 = 0, n3 = 0;原创 2013-07-23 19:22:08 · 589 阅读 · 0 评论 -
[leetcode]word search
class Solution { public: bool dfs(vector > &board, string word, int i, int j){ int M = board.size(); int N = board[0].size(); if(i = M || j >= N || board[i][j]!=wo原创 2013-07-22 13:47:08 · 884 阅读 · 0 评论 -
[leetcode]Spiral Matrix II
class Solution { public: vector > generateMatrix(int n) { // Start typing your C/C++ solution below // DO NOT write int main() function if(n == 0) return vector>();原创 2013-07-29 22:25:30 · 788 阅读 · 0 评论 -
[leetcode]Rotate List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *ro原创 2013-07-28 23:19:21 · 691 阅读 · 0 评论 -
[leetcode]Spiral Matrix
class Solution { public: vector spiralOrder(vector > &matrix) { // Start typing your C/C++ solution below // DO NOT write int main() function if(matrix.empty()) return vect原创 2013-07-29 00:19:36 · 825 阅读 · 0 评论 -
[leetcode]Pow(x, n)
class Solution { public: double powPositive(double x, int n){ if(n == 0) return 1; if(n == 1) return x; double tmp; if(n%2 == 0){ tmp = powPosi原创 2013-08-02 15:57:32 · 580 阅读 · 0 评论 -
[leetcode]Unique Paths II
class Solution { public: int uniquePathsWithObstacles(vector > &obstacleGrid) { // Start typing your C/C++ solution below // DO NOT write int main() function if(obstacleGri原创 2013-07-26 12:40:59 · 610 阅读 · 0 评论 -
[leetcode]Minimum Path Sum
class Solution { public: int minPathSum(vector > &grid) { // Start typing your C/C++ solution below // DO NOT write int main() function if(grid.empty()) return 0;原创 2013-07-26 09:19:52 · 652 阅读 · 0 评论 -
[leetcode]Merge Two Sorted Lists
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *me原创 2013-07-25 20:37:12 · 630 阅读 · 0 评论 -
[leetcode]Unique Paths
class Solution { public: int uniquePaths(int m, int n) { // Start typing your C/C++ solution below // DO NOT write int main() function vector> f(m, vector(n, 1));原创 2013-07-26 12:25:42 · 838 阅读 · 1 评论 -
[leetcode]Sqrt(x)
class Solution { public: int sqrt(int x) { // Start typing your C/C++ solution below // DO NOT write int main() function if(x < 1) return 0; if(x == 1) return 1;原创 2013-07-24 22:19:27 · 603 阅读 · 0 评论 -
[leetcode]Simplify Path
class Solution { public: string simplifyPath(string path) { // Start typing your C/C++ solution below // DO NOT write int main() function if(path.empty()) return "";原创 2013-07-24 21:57:46 · 524 阅读 · 0 评论 -
[leetcode]N-Queens
64ms过大集合 class Solution { vector> result; public: bool canPlace(int i, int j, vector &tmp, int n){ if(i == 0) return true; for(int k = 0; k < i; k++){ if(tmp[k][j]原创 2013-07-31 11:43:24 · 692 阅读 · 0 评论 -
[leetcode]Add Binary
class Solution { public: char add(char a, char b, char c, char &carry){ int result = a - '0' + b -'0' + c-'0'; if(result == 0){ carry = '0'; return '0';原创 2013-07-24 22:57:56 · 590 阅读 · 0 评论 -
[leetcode]Plus One
class Solution { public: vector plusOne(vector &digits) { // Start typing your C/C++ solution below // DO NOT write int main() function if(digits.empty()) return vector();原创 2013-07-24 22:31:38 · 553 阅读 · 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 <= 2) return n; vector原创 2013-07-24 22:02:14 · 562 阅读 · 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 if(n == 0) return 0; if(n =原创 2013-07-31 10:45:12 · 760 阅读 · 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 == 1) return 0; vect原创 2013-07-30 21:44:31 · 615 阅读 · 0 评论 -
[leetcode]Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the f原创 2013-07-04 10:38:14 · 615 阅读 · 0 评论 -
[leetcode]Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. /** * Definition for binary tree原创 2013-07-02 20:44:50 · 628 阅读 · 0 评论