随笔分类 - LeetCode题解
摘要:1 class Solution 2 { 3 public: 4 int climbStairs(int n) 5 { 6 vector<int> nums(n + 10); 7 nums[1] = 1; 8 nums[2] = 2; 9 for(int i = 3;i <= n;i ++) num
阅读全文
摘要:1 class Solution 2 { 3 public: 4 int mySqrt(int x) 5 { 6 double l = 0; 7 double r = x; 8 9 while(r - l > 1e-6) 10 { 11 double mid = (l + r)/2; 12 if(m
阅读全文
摘要:1 class Solution 2 { 3 public: 4 string addBinary(string a, string b) 5 { 6 if(a.size() < b.size()) swap(a,b); 7 int C = 0;//进位 8 int m = a.size(),n =
阅读全文
摘要:1 class Solution 2 { 3 public: 4 vector<int> plusOne(vector<int>& digits) 5 { 6 int n = digits.size(); 7 int C = 1;//进位 8 for(int i = n - 1;i >= 0;i -
阅读全文
摘要:1 class Solution 2 { 3 public: 4 int minPathSum(vector<vector<int>>& grid) 5 { 6 int m = grid.size(); 7 int n = grid[0].size(); 8 vector<vector<int>>
阅读全文
摘要:STL中next_permutation:下一个排列 prev_permutation:上一个排列 1 class Solution 2 { 3 public: 4 string getPermutation(int n, int k) 5 { 6 string str; 7 for(int i =
阅读全文
摘要:1 class Solution 2 { 3 vector<vector<int>> ans; 4 int a; 5 public: 6 vector<vector<int>> generateMatrix(int n) 7 { 8 a = 1; 9 ans = vector<vector<int>
阅读全文
摘要:1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), next(NULL) {} 7 * };
阅读全文
摘要:1 class Solution 2 { 3 public: 4 int uniquePathsWithObstacles(vector<vector<int>>& nums) 5 { 6 int m = nums.size(); 7 int n = nums[0].size(); 8 9 //起点
阅读全文
摘要:1 class Solution 2 { 3 public: 4 int uniquePaths(int m, int n) 5 { 6 vector<vector<int>> dp(m,vector<int>(n,1)); 7 for(int i = 1;i < m;i ++) 8 { 9 for
阅读全文
摘要:1 class Solution 2 { 3 void spilt(string s,char c,vector<string> &res) 4 { 5 istringstream iss(s); 6 string temp; 7 while(getline(iss,temp,c)) 8 { 9 /
阅读全文
摘要:1 class Solution 2 { 3 public: 4 vector<vector<int>> merge(vector<vector<int>>& nums) 5 { 6 vector<vector<int>> res; 7 if(nums.empty()) return res; 8
阅读全文
摘要:1 class Solution 2 { 3 public: 4 bool canJump(vector<int>& nums) 5 { 6 int n = nums.size(); 7 int max_size = nums[0]; 8 for(int i = 0;i < n;i ++) 9 {
阅读全文
摘要:1 class Solution 2 { 3 vector<int> ans; 4 public: 5 vector<int> spiralOrder(vector<vector<int>>& matrix) 6 { 7 if(matrix.size() == 0) return {}; 8 int
阅读全文
摘要:1 class Solution 2 { 3 public: 4 int longestCommonSubsequence(string text1, string text2) 5 { 6 int m = text1.size(); 7 int n = text2.size(); 8 vector
阅读全文
摘要:1 class Solution 2 { 3 public: 4 int findNumberOfLIS(vector<int>& nums) 5 { 6 if(nums.size() == 0) return 0; 7 int n = nums.size(); 8 vector<int> dp(n
阅读全文
摘要:1 class Solution 2 { 3 public: 4 int lengthOfLIS(vector<int>& nums) 5 { 6 if(nums.size() == 0) return 0; 7 int n = nums.size(); 8 int res = INT_MIN; 9
阅读全文
摘要:1 //看成一个下三角形 2 class Solution 3 { 4 public: 5 int minimumTotal(vector<vector<int>>& triangle) 6 { 7 int n = triangle.size(); 8 int res = INT_MAX; 9 ve
阅读全文
摘要:1 class Solution 2 { 3 public: 4 int maxSubArray(vector<int>& nums) 5 { 6 int n = nums.size(); 7 vector<int> dp(n + 5,0); 8 dp[0] = nums[0]; 9 int res
阅读全文
摘要:思路跟51题一模一样 1 class Solution 2 { 3 vector<vector<string>> res; 4 vector<string> temp;//临时路径 5 vector<bool> col,m,s;//列,主对角线,副对角线 6 int n; 7 public: 8 i
阅读全文

浙公网安备 33010602011771号