![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
文章平均质量分 69
jambee
这个作者很懒,什么都没留下…
展开
-
Plus One
class Solution { public: vector plusOne(vector &digits){ int count = digits.size(); digits[count-1] += 1; while(count--){ if(digits[count] >=10 && count >=1){ digits[count] %= 10; d原创 2014-10-21 20:29:41 · 164 阅读 · 0 评论 -
Remove Nth Node From End of List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *re原创 2014-10-27 10:51:09 · 134 阅读 · 0 评论 -
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原创 2014-10-27 12:35:02 · 152 阅读 · 0 评论 -
Unique Paths II
class Solution { public: int uniquePathsWithObstacles(vector > &obstacleGrid) { // Start typing your C/C++ solution below // DO NOT write int main() function vector > f(obs转载 2014-11-13 15:17:46 · 180 阅读 · 0 评论 -
Reverse Linked List II
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *re原创 2014-10-28 15:04:26 · 172 阅读 · 0 评论 -
Sort List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *mergeT原创 2014-10-29 18:42:15 · 208 阅读 · 0 评论 -
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原创 2014-10-29 16:53:26 · 128 阅读 · 0 评论 -
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原创 2014-10-29 15:06:16 · 213 阅读 · 0 评论 -
Valid Sudoku
class Solution { public: bool isLineOk(vector &board){ //1到9,没有重复 map roman; roman['1']=0; roman['2']=0; roman['3']=0; roman['4']=0; roman['5']=0; roman['6']=0; roman['7']=0; roman['8']=原创 2014-11-03 18:00:15 · 137 阅读 · 0 评论 -
Sudoku Solver
bool isValid(vector > &board, int a, int b) { for (int i = 0; i < 9; ++i) { if (i != a && board[i][b] == board[a][b]) return false; } for (int j = 0; j < 9; ++j) { if (j != b && board[a][j]转载 2014-11-04 17:00:25 · 130 阅读 · 0 评论 -
Anagrams
class Solution { public: vector anagrams(vector &strs) { string s; map anagram; vector res; for (int i = 0; i < strs.size(); ++i) { s = strs[i];转载 2014-11-04 21:29:24 · 131 阅读 · 0 评论 -
Remove Duplicates from Sorted Array II
class Solution { public: int removeDuplicates(int A[], int n) { if(n<1) return 0; if(n==1) return 1; int index = 2; for(int i=2;i<n;i++){原创 2014-10-21 14:25:55 · 142 阅读 · 0 评论 -
Remove Element
class Solution { public: int removeElement(int A[], int n, int elem) { int index = 0; for(int i=0;i<n;i++){ if(A[i] != elem) A[index++] = A[i]; }原创 2014-10-21 16:31:01 · 200 阅读 · 0 评论 -
Merge Sorted Array
class Solution { public: void merge(int A[], int m, int B[], int n) { int length = m+n; int Ai = m-1; int Bi = n-1; for(int i=length-1 ;i>=0;i--){ if(Ai >=0 && Bi>=0){ if(A[Ai] >原创 2014-10-21 19:26:32 · 127 阅读 · 0 评论 -
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原创 2014-11-06 13:37:17 · 138 阅读 · 0 评论 -
4Sum
class Solution { public: vector > fourSum(vector &num, int target) { vector > ret; int len = num.size(); if(len < 4) return ret; vector num2; num2.assign(num.begin(), num.end()); sort( num原创 2014-11-13 14:15:32 · 176 阅读 · 0 评论 -
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原创 2014-10-27 15:39:48 · 121 阅读 · 0 评论 -
Add Two Numbers
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *ad原创 2014-10-27 10:16:22 · 169 阅读 · 0 评论 -
Two Sum
class Solution { public: vector twoSum(vector &numbers, int target) { vector result; unordered_map mapping; for(int i=0;i<numbers.size();i++){ mapping[numbers[i]]=i; } for(int i=0;i<numbe原创 2014-10-21 21:23:04 · 183 阅读 · 0 评论 -
3Sum Closest
class Solution { public: int threeSumClosest(vector &num, int target) { int count = num.size(); int result = 0; sortPro(num); result = abs(num[0]+num[1]+num[2] -target); int cc = num[原创 2014-10-22 11:01:11 · 169 阅读 · 0 评论 -
Roman to Integer
class Solution { public: int romanToInt(string s) { map roman; roman['I']=1; roman['V']=5; roman['X']=10; roman['L']=50; roman['C']=100; roman['D']=500; roman['M']=1000; int length原创 2014-10-22 21:00:43 · 118 阅读 · 0 评论 -
Add Binary
class Solution { public: string addBinary(string a, string b) { string c; int ai = a.length()-1; int bi = b.length()-1; int ml = ai>bi?ai:bi; int q = 0; for(int i=0;i<=ml;i++,ai--,bi-原创 2014-10-22 19:45:11 · 254 阅读 · 0 评论 -
Sqrt(x)
class Solution { public: int sqrt(int x) { if(x<0) return -1; if(x=0) return 0; int left = 0; int right = x; long long mid = 0;原创 2014-10-24 09:21:26 · 184 阅读 · 0 评论 -
Palindrome Number
class Solution { public: bool isPalindrome(int x) { int wei = 1; int result = x; if( x < 0) return false; while(result >= 10){ wei++;原创 2014-10-23 16:02:56 · 174 阅读 · 0 评论 -
Permutation Sequence
class Solution { public: int uniquePro(int n){ int sum = 1; while(n){ sum *= n; n--; } return sum; } string getPermutation(int n, int k) { stringstream ss; vector res; for(int i=1;i<=原创 2014-10-23 20:35:07 · 154 阅读 · 0 评论 -
Reverse Integer
class Solution { public: int reverse(int x) { int temp = x,temp1 = x; if(x<0){ temp *= -1; temp1 *= -1; } int result = 0; int wei = 1; while( temp >= 10){ wei++; temp /= 10;原创 2014-10-23 16:20:12 · 121 阅读 · 0 评论 -
String to Integer (atoi)
class Solution { public: int atoi(const char *str) { if(str == NULL) return 0; if(*str == '\0') return 0; long long res = 0; //去除空格 while(*str == ' ') str++; bool ispositive = t原创 2014-10-23 17:01:02 · 194 阅读 · 0 评论 -
Multiply Strings
class Solution { public: string multiply(string num1, string num2) { stringstream ss; bool ispositive = true; vector s_num1; vector s_num2; //positive int length1 = num1.size(); int length2 = nu原创 2014-10-24 14:01:02 · 149 阅读 · 0 评论 -
Max Points on a Line
class Solution { public: //判断点是否在直线上,就是判断斜率是否相同 int maxPoints(vector &points) { int maxLine = 0; if(points.size() <=2) return points.size(); for (int原创 2014-10-25 21:23:25 · 179 阅读 · 0 评论 -
Integer to Roman
class Solution { public: string cc(int num){ if(num=0){ switch(num){ case 0: return "";break; case 1: return "I";break; case 2: return "II";break; case 3: return "III";break; case 4: retu原创 2014-10-24 15:15:53 · 189 阅读 · 0 评论 -
Divide Two Integers
long long internalDivide(unsigned long long dividend,unsigned long long divisor){ if (dividend<divisor) { return 0; } long long result = 1; unsigned long long tmp = divisor,left; while (tmp<=d原创 2014-10-25 21:24:48 · 124 阅读 · 0 评论 -
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原创 2014-10-27 13:12:39 · 117 阅读 · 0 评论 -
Construct Binary Tree from Inorder and Postorder Traversal
/** /** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class So转载 2014-11-06 13:37:50 · 123 阅读 · 0 评论