自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 75. 颜色分类

荷兰国旗问题 class Solution { public: void sortColors(vector<int>& nums) { int n = nums.size(), l = 0, r = n-1; while(l < r){ while(l < n && nums[l] == 0) l++; while(r > 0 && nums[r

2020-05-15 11:48:37 88

原创 70. 爬楼梯

class Solution { public: int climbStairs(int n) { if(n < 3) return n; int ans, x = 1, y = 2; for(int i = 3; i <= n; i++){ ans = x + y; x = y; y = ans; } return ans; .

2020-05-12 20:45:53 77

原创 62. 不同路径

class Solution { public: int uniquePaths(int m, int n) { vector<int> v(m, 1); for(int i = n-2; i >= 0; i--){ for(int j = m-2; j >= 0; j--) v[j] += v[j+1]; } return v[0]; } };.

2020-05-11 22:51:05 81

原创 56. 合并区间

class Solution { public: vector<vector<int>> merge(vector<vector<int>>& intervals) { if(!intervals.size()) return intervals; sort(intervals.begin(), intervals.end()); int k = 0; for(int i = 1.

2020-05-09 12:06:08 59

原创 55. 跳跃游戏

class Solution { public: bool canJump(vector<int>& nums) { int site = 0; for(int i = 0; i < nums.size(); i++){ if(site < i) return false; s...

2020-05-04 17:05:42 68

原创 53. 最大子序和

class Solution { public: int maxSubArray(vector<int>& nums) { int maxSum = nums[0]; for(int i = 1; i < nums.size(); i++){ if(nums[i-1] > 0) ...

2020-05-04 16:19:56 66

原创 49. 字母异位词分组

class Solution { public: vector<vector<string>> groupAnagrams(vector<string>& strs) { vector<vector<string>> res; unordered_map<string, int&gt...

2020-05-03 09:13:34 57

原创 48. 旋转图像

class Solution { public: void rotate(vector<vector<int>>& matrix) { for(int i = 0; i < matrix.size(); i++){ for(int j = i+1; j < matrix[0].size(); j++){ ...

2020-05-03 08:08:14 52

原创 46. 全排列

交换法 class Solution { private: vector<vector<int>> res; void backtrack(vector<int>& nums, int start, int end){ if(start >= end){ res.push_back(num...

2020-05-01 20:19:41 68

原创 33. 搜索旋转排序数组

class Solution { public: int search(vector<int>& nums, int target) { int n = nums.size(), l = 0, r = n-1, mid; while(l <= r){ mid = l + (r-l)/2; ...

2020-04-28 23:17:22 41

原创 31. 下一个排列

class Solution { public: void nextPermutation(vector<int>& nums) { if(nums.size() < 2) return; int i = nums.size()-1, j = i; while(i && nums[i] <= ...

2020-04-27 17:32:27 69

原创 21. 合并两个有序链表

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

2020-04-27 16:23:52 60

原创 20. 有效的括号

class Solution { public: bool isValid(string s) { stack<char> stc; map<char, char> m{{'(',')'}, {'[',']'}, {'{','}'}}; for(auto c:s){ if(!stc.empty...

2020-04-27 15:32:11 64

原创 19. 删除链表的倒数第N个节点

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

2020-04-24 16:54:56 64

原创 17. 电话号码的字母组合

result = [] def backtrack(路径, 选择列表): if 满足结束条件: result.add(路径) return for 选择 in 选择列表: 做选择 backtrack(路径, 选择列表) 撤销选择 class Solution { private: ...

2020-04-24 16:30:26 100

原创 11. 盛最多水的容器

class Solution { public: int maxArea(vector<int>& height) { int n = height.size(), l = 0, r = n-1, mArea = 0; while(l < r){ int h = min(height[l], height[...

2020-04-22 12:13:02 70

原创 5. 最长回文子串

class Solution { public: string longestPalindrome(string s) { int n = s.size(); if(n < 2) return s; vector<vector<bool>> dp(n, vector<bool>(n...

2020-04-20 15:53:44 106

原创 3. 无重复字符的最长子串

class Solution { public: int lengthOfLongestSubstring(string s) { unordered_set<char> us; int n = s.size(), l = 0, r = 0, maxLen = 0; while(r < n){ wh...

2020-04-18 17:25:09 71

原创 2. 两数相加

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

2020-04-16 19:46:56 107

原创 1. 两数之和

class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { map<int, int> m; for(int i = 0; i < nums.size(); i++){ if(m.find(...

2020-04-15 11:13:32 143

空空如也

空空如也

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

TA关注的人

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