自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(59)
  • 收藏
  • 关注

原创 leetcode-29-divide two integer

class Solution {public: int divide(int dividend, int divisor) { bool flag = (dividend<0 && divisor>0) || (dividend>0 && divisor<0); long long tmp1 = a...

2018-08-24 15:53:05 203

原创 leetcode-24-swap nodes in pairs

/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* s...

2018-08-24 12:40:16 170

原创 leetcode-22-generate parantheses

class Solution {public: vector<string> generateParenthesis(int n) { vector<string> result; searchDfs(n, n, "", result); return result; } void sea...

2018-08-24 11:10:18 222

原创 leetcode-19-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* r...

2018-08-24 10:08:19 145

原创 leetcode-18-4sum

class Solution {public: vector<vector<int>> fourSum(vector<int>& nums, int target) { if(nums.size() < 4){ return {}; } vector<vect...

2018-08-23 17:01:10 145

转载 leetcode-17-combinations of a phone number

class Solution {public: vector<string> letterCombinations(string digits) { vector<string> ans; if(digits.size() == 0) return ans; int depth = di...

2018-08-23 11:16:29 160

原创 leetcode-16-3sum closest

class Solution {public: vector<vector<int>> threeSum(vector<int>& nums) { if(nums.size() < 3){ return {}; } vector<vector<int&g...

2018-08-22 19:51:55 149

原创 leetcode-15-3sum

class Solution {public: vector<vector<int>> threeSum(vector<int>& nums) { if(nums.size() < 3){ return {}; } vector<vector<int&g...

2018-08-22 17:20:07 129

原创 leetcode-12-integer to roman

class Solution {public: string intToRoman(int num) { string result = ""; vector<int> val{1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; vector<string>...

2018-08-22 15:12:55 144

原创 leetcode-11-container with most water

class Solution {public: int maxArea(vector<int>& height) { int i = 0; int j = height.size()-1; int result = 0; while(i < j){ result = max...

2018-08-22 15:04:51 177

原创 leetcode-8-string to integer(atoi)

class Solution {public: int myAtoi(string str) { int len = str.size(); long long result = 0; int index; bool flag = false; for(int i=0; i<len;...

2018-08-22 11:08:05 217

原创 leetcode-6-zigzag conversion

class Solution {public: string convert(string s, int numRows) { if(s.size() == 1 || numRows == 1){ return s; } int len = s.size(); i...

2018-08-22 09:56:53 141

原创 leetcode-191-number of 1 bits

class Solution {public: int hammingWeight(uint32_t n) { int result = 0; for(int i=0; i<32; i++){ if(n == 0){ break; } ...

2018-08-22 09:05:53 128

原创 leetcode-190-reverse bits

class Solution {public: uint32_t reverseBits(uint32_t n) { uint32_t result = 0; for(int i=0; i<32; i++){ if(n & 1 == 1){ result = (res...

2018-08-22 08:54:10 141

原创 leetcode-189-rotate array

class Solution {public: void rotate(vector<int>& nums, int k) { if( nums.empty() || (k %= nums.size()) == 0){ return; } int n = nums.size()...

2018-08-22 08:42:16 148

原创 leetcode-172-Factorial Trailing Zeroes

class Solution {public: int trailingZeroes(int n) { int i = 1; int result = 0; while(pow(5,i)<=n){ result += (n / pow(5,i)); i++; } ...

2018-07-29 14:17:31 188

原创 leetcode-171-excel sheet column number

class Solution {public: int titleToNumber(string s) { int len = s.size(); char single = 64; int p; int sum=0; for(int i=len-1;i>=0;i--){ p ...

2018-07-29 14:04:04 159

原创 leetcode-169-majority element

class Solution {public: int majorityElement(vector<int>& nums) { int len = nums.size(); map<int,int> result; for(int i=0;i<len;i++){ result...

2018-07-29 13:53:35 135

原创 leetcode-168-excel sheet column title

class Solution {public: string convertToTitle(int n) { string result = ""; while(n) { result = (char)((n-1)%26+'A') + result; n = (n-1)/26; ...

2018-07-29 11:19:39 199

原创 leetcode-167-two sum II- input array is sorted

class Solution {public: vector<int> twoSum(vector<int>& numbers, int target) { int len = numbers.size(); vector<int> result={}; int i = 0, j = len-1...

2018-07-29 10:42:48 141

原创 leetcode-160-intersection of two linked lists

/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *g...

2018-07-29 10:09:30 191

原创 leetcode-145-min stack

class MinStack {private: stack<int> stk; stack<int> min;public: /** initialize your data structure here. */ MinStack() { } void push(int x) { ...

2018-07-24 21:05:22 165

原创 leetcode-141-link list cycle

/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: bool hasCyc...

2018-07-24 20:45:54 273

原创 leetcode-136-single number

class Solution {public: int singleNumber(vector<int>& nums) { int result = 0; for(auto x:nums){ result ^= x; } return result; }...

2018-07-24 20:27:50 135

原创 leetcode-125-valid palindrome

class Solution {public: bool isPalindrome(string s) { if(s.empty() == true) return true; string result=""; for(auto x:s){ if(isa...

2018-07-24 20:11:17 136

原创 leetcode-122-best time to buy and sell stock II

class Solution {public: int maxProfit(vector<int>& prices) { int max=0; int len = prices.size(); for(int i=1;i<len;i++){ if(prices[i]>prices[i-...

2018-07-09 21:49:01 215

原创 leetcode-121-best time to buy and sell stock

class Solution {public: int maxProfit(vector<int>& prices) { int len = prices.size(); int max = 0; for(int i=0;i<len-1;i++){ for(int j=i+1;j<le...

2018-07-09 21:38:03 139

原创 leetcode-119-pascal's triangle

class Solution {public: vector<int> getRow(int rowIndex) { vector<vector<int>> result; vector<int> ele={}; int ini=1; for(int i=0 ; i<ro...

2018-07-09 21:00:09 191

原创 leetcode-118-pascal's triangle

class Solution {public: vector<vector<int>> generate(int numRows) { vector<vector<int>> result; vector<int> ele={}; int ini=1; for(in...

2018-07-08 21:54:18 175

原创 leetcode-112-path sum I

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas...

2018-07-08 21:19:23 167

原创 leetcode-111-minimum depth of 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) {} * }; */clas...

2018-07-08 20:34:14 107

原创 leetcode-110-balanced 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) {} * }; */clas...

2018-07-08 18:25:23 215

原创 leetcode-108-convert sorted array to 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) {} * }; */clas...

2018-07-08 17:21:03 100

原创 leetcode-107-Binary Tree Level Order Traversal II

自己写的代码,只考虑到了最后一层叶子节点为NULL的情况,没有考虑到中间level会有NULL的情况/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) :...

2018-07-08 16:24:23 92

原创 leetcode-104-maximum depth of 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) {} * }; */clas...

2018-07-04 20:05:17 141

原创 leetcode-101-symmetric tree

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas...

2018-06-24 22:07:38 126

原创 leetcode-100-same tree

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas...

2018-06-24 21:55:02 134

原创 leetcode-88-merge sorted array

class Solution {public: void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) { int count = m + n - 1; m = m - 1; n = n - 1; while(c...

2018-06-24 20:57:47 108

原创 leetcode-83-remove duplicates from sorted lists

/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* de...

2018-06-24 12:18:41 133

原创 leetcode-70-climb stairs

class Solution {public: int climbStairs(int n) { int dp[3]; dp[0]=1; dp[1]=2; int i=n; while(i > 2){ dp[2]=dp[0]+dp[1]; dp[0]=dp...

2018-06-17 13:22:32 138

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除