- 博客(42)
- 收藏
- 关注
原创 leetcode 415. Add Strings
class Solution {public: string addStrings(string num1, string num2) { int l1 = num1.length(); int l2 = num2.length(); string s; int c=0,i=l1-1,j=l2-1,count=0;; ...
2019-04-16 09:08:36 158
原创 leetcode 914. X of a Kind in a Deck of Cards
#include<algorithm>#include<map>class Solution {public: bool hasGroupsSizeX(vector<int>& deck) { int l = deck.size(); if(l<2)return false; map...
2019-04-14 22:43:09 184
原创 leetcode 561. Array Partition I
class Solution {public: bool isOneBitCharacter(vector<int>& bits) { int l = bits.size(); int i=0; while(i<l-1) { if(bits[i]==1) ...
2019-04-14 21:47:55 152
原创 leetcode 796. Rotate String
class Solution {public: bool rotateString(string A, string B) { int l1 = A.length(); int l2 = B.length(); if(l1!=l2)return false; if(l1==0)return true; ...
2019-04-14 21:33:46 133
原创 leetcode 917. Reverse Only Letters
class Solution {public: bool isString(char s) { if((s<='z'&&s>='a')||(s<='Z'&&s>='A')) return true; else return false; } strin...
2019-04-14 21:12:09 173
原创 leetcode 557. Reverse Words in a String III
#include<stack>class Solution {public: string reverseWords(string s) { int l = s.length(); int i = 0; string res; stack<char> tmp; w...
2019-04-13 15:51:51 2281
原创 leetcode 762. Prime Number of Set Bits in Binary Representation
#include<cmath>class Solution {public: bool isPrime(int l) { if(l==0||l==1)return false; if(l==2||l==3)return true; for(int i=2;i<=sqrt(l);i++) { ...
2019-04-13 13:55:16 116
原创 leetcode 830. Positions of Large Groups
class Solution {public: vector<vector<int>> largeGroupPositions(string S) { int l = S.length(); vector<vector<int>> t; int i=0; w...
2019-04-12 22:44:22 102
原创 leetcode 1013. Partition Array Into Three Parts With Equal Sum
class Solution {public: bool canThreePartsEqualSum(vector<int>& A) { int l = A.size(); int sum=0; int i; for(i=0;i<l;i++) sum+=A[i]; ...
2019-04-12 22:32:19 231
原创 leetcode 700. Search in a Binary Search Tree
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */cla...
2019-04-12 22:05:52 203
原创 leetcode 852. Peak Index in a Mountain Array
class Solution {public: int peakIndexInMountainArray(vector<int>& A) { int l =A.size(); int i=0,j=l-1; for(i;i<l-1;i++) { if(A[i]<A[i+...
2019-04-12 21:46:19 142
原创 leetcode 606. Construct String from Binary Tree
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */cla...
2019-04-12 21:13:39 118
原创 leetcode 944. Delete Columns to Make Sorted
class Solution {public: int minDeletionSize(vector<string>& A) { int l = A.size(); int s = A[0].length(); int count =s; for(int i=0;i<s;i++)...
2019-04-12 20:33:06 137
原创 leetcode 671. Second Minimum Node In a Binary Tree
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */cla...
2019-04-12 16:44:26 129
原创 leetcode 566. Reshape the Matrix
class Solution {public: vector<vector<int>> matrixReshape(vector<vector<int>>& nums, int r, int c) { vector<vector<int>> res(r); int m=num...
2019-04-12 16:09:13 98
原创 leetcode 461. Hamming Distance
class Solution {public: int hammingDistance(int x, int y) { int count = 0; while(x&&y) { int r1 = x%2; int r2 = y%2; if(r1!=r2...
2019-04-12 15:40:05 101
原创 leetcode 896. Monotonic Array
class Solution {public: bool isMonotonic(vector<int>& A) { bool increase=false; if(A.size()==0||A.size()==1)return true; int i; for(i=0;i<A....
2019-04-12 15:29:33 129
原创 leetcode 575. Distribute Candies
class Solution {public: int distributeCandies(vector<int>& candies) { set<int> cl; int count = 0; for(int i=0;i<candies.size();i++) { ...
2019-04-10 10:30:11 161
原创 leetcode 500. Keyboard Row
class Solution {public: vector<string> findWords(vector<string>& words) { int alpha[26] ={1,2,2,1,0,1,1,1,0,1,1,1,2,2,0,0,0,0,1,0,0,2,0,2,0,2}; vector<string&g...
2019-04-10 10:01:28 137
原创 leetcode 509. Fibonacci Number
class Solution {public: int fib(int N) { if(N==0)return 0; if(N==1)return 1; int first=0,second=1; for(int i=2;i<=N;i++) { int tmp = first+...
2019-04-10 09:52:16 182
原创 leetcode 590. N-ary Tree Postorder Traversal
/*// Definition for a Node.class Node {public: int val; vector<Node*> children; Node() {} Node(int _val, vector<Node*> _children) { val = _val; childr...
2019-04-09 21:53:58 158
原创 leetcode 806. Number of Lines To Write String
class Solution {public: vector<int> numberOfLines(vector<int>& widths, string S) { vector<int> last; last.push_back(0); last.push_back(0); i...
2019-04-09 09:19:26 67
原创 leetcode 559. Maximum Depth of N-ary Tree
/*// Definition for a Node.class Node {public: int val; vector<Node*> children; Node() {} Node(int _val, vector<Node*> _children) { val = _val; childr...
2019-04-09 08:55:04 74
原创 leetcode 617. Merge Two Binary Trees
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */cla...
2019-04-08 22:28:11 116
原创 leetcode 617. Merge Two Binary Trees
class Solution {public: int numJewelsInStones(string J, string S) { int count = 0; for(int i=0;i<J.length();i++) { for(int k = 0;k<S.length();k++) ...
2019-04-08 22:24:25 87
原创 leetcode 443. String Compression
#include<stack>class Solution {public: int compress(vector<char>& chars) { char tmp=chars[0]; int count =1; int sum = 0; int j=0; for(int...
2019-04-08 22:11:14 95
原创 leetcode 965. Univalued Binary Tree
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */cla...
2019-04-08 21:33:38 75
原创 leetcode 985. Sum of Even Numbers After Queries
class Solution {public: vector<int> sumEvenAfterQueries(vector<int>& A, vector<vector<int>>& queries) { int l1 = A.size(); int l2 = queries.size()...
2019-04-08 20:58:53 106
原创 leetcode 832. Flipping an Image
class Solution {public: vector<vector<int>> flipAndInvertImage(vector<vector<int>>& A) { int m = A.size(); int n = A[0].size(); // cout<<...
2019-04-08 15:08:02 95
原创 leetcode 897. Increasing Order Search Tree
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */cla...
2019-04-08 14:59:45 100
原创 leetcode 367. Valid Perfect Square
class Solution {public: bool isPerfectSquare(int num) { int i = 1; while(num>0) { num = num -i; i = i + 2; } if(num==0...
2019-04-07 15:58:18 62
原创 leetcode 977. Squares of a Sorted Array
#include<vecor>class Solution {public: void quick_sort(vector<int> &num, int low1, int high1) { int tmp = num[low1]; int low = low1,high = high1; if(...
2019-04-07 15:40:58 76
原创 leetcode 804. Unique Morse Code Words
#include<set>class Solution {public: string code[26]={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",...
2019-04-07 15:20:09 77
原创 leetcode 728. Self Dividing Numbers
#include<vector>class Solution {public: bool self_divide(int num) { int tmp = num; while(tmp>0) { int r = tmp%10; if(r==0||num%r!=0)...
2019-04-07 15:13:36 75
原创 leetcode 922. Sort Array By Parity II
class Solution {public: vector<int> sortArrayByParityII(vector<int>& A) { int l = A.size(); int i =0,j=1; while(i<l&&j<l) { ...
2019-04-07 15:07:47 145
原创 leetcode 905. Sort Array By Parity
class Solution {public: vector<int> sortArrayByParity(vector<int>& A) { int l = A.size(); int low = 0,high =l-1; while(low<high) { ...
2019-04-07 10:28:48 57
原创 leetcode 876. Middle of the Linked List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* m...
2019-04-06 11:09:22 50
原创 leetcode 872. Leaf-Similar Trees
#include<queue>#include<vector>/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val...
2019-04-06 10:09:27 73
原创 leetcode 868. Binary Gap
class Solution {public: int binaryGap(int N) { int max =0; int start=0,i=0; bool first = true; while(N) { int r = N%2; if(r==1&...
2019-04-05 21:49:27 77
原创 leetcode 860. Lemonade Change
class Solution {public: bool lemonadeChange(vector<int>& bills) { int l = bills.size(); if(l==0)return true; if(bills[0]>5)return false; int remian[2...
2019-04-05 21:33:28 115
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人