摘要:
1 //KMP算法 2 class Solution 3 { 4 public: 5 //求next数组 6 vector<int> pre(string& str2) 7 { 8 if(str2.size() == 1) return {-1}; 9 vector<int> next(str2.s 阅读全文
posted @ 2020-03-15 18:42
Jinxiaobo0509
阅读(120)
评论(0)
推荐(0)
摘要:
1 //跟上一题一样的思路 2 class Solution 3 { 4 public: 5 int removeElement(vector<int>& nums, int val) 6 { 7 vector<int> vec; 8 int j = 0; 9 for(int i = 0;i < n 阅读全文
posted @ 2020-03-15 18:41
Jinxiaobo0509
阅读(198)
评论(0)
推荐(0)
摘要:
1 //双指针算法,也就是实现STL中的unique函数 2 class Solution 3 { 4 public: 5 int removeDuplicates(vector<int>& nums) 6 { 7 int n = nums.size(); 8 int j = 0; 9 for(in 阅读全文
posted @ 2020-03-15 18:40
Jinxiaobo0509
阅读(131)
评论(0)
推荐(0)
摘要:
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 * }; 阅读全文
posted @ 2020-03-15 18:39
Jinxiaobo0509
阅读(131)
评论(0)
推荐(0)
摘要:
1 //这道题没有思路,借鉴别人的代码 2 3 4 //1、使用递归。 5 //2、每次可以放置左括号的条件是当前左括号的数目不超过 nn。 6 //3、每次可以放置右括号的条件是当前右括号的数目不超过左括号的数目。 7 class Solution 8 { 9 vector<string> res 阅读全文
posted @ 2020-03-15 18:38
Jinxiaobo0509
阅读(135)
评论(0)
推荐(0)
摘要:
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 * }; 阅读全文
posted @ 2020-03-15 18:36
Jinxiaobo0509
阅读(97)
评论(0)
推荐(0)
摘要:
1 //思路很清晰,直接用stack 2 class Solution 3 { 4 unordered_map<char,char> hash = {{'(',')'},{'[',']'},{'{','}'}}; 5 public: 6 bool isValid(string s) 7 { 8 st 阅读全文
posted @ 2020-03-15 18:35
Jinxiaobo0509
阅读(96)
评论(0)
推荐(0)
摘要:
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 * }; 阅读全文
posted @ 2020-03-15 18:34
Jinxiaobo0509
阅读(100)
评论(0)
推荐(0)
摘要:
1 //跟三数之和思想一样的,只不过多一层循环 2 class Solution 3 { 4 public: 5 vector<vector<int>> fourSum(vector<int>& nums, int target) 6 { 7 vector<vector<int>> res; 8 i 阅读全文
posted @ 2020-03-15 18:33
Jinxiaobo0509
阅读(116)
评论(0)
推荐(0)
摘要:
1 //DFS问题一直很难 2 class Solution 3 { 4 void dfs(string digits,vector<vector<char>>& d,vector<string> &res,int cur,string& temp) 5 { 6 if(cur == digits.s 阅读全文
posted @ 2020-03-15 18:32
Jinxiaobo0509
阅读(144)
评论(0)
推荐(0)
摘要:
1 //搞清楚各个变量的含义 2 //***忘记对数组进行排序,以至于一直卡在这里*** 3 class Solution 4 { 5 public: 6 int threeSumClosest(vector<int>& nums, int target) 7 { 8 int n = nums.si 阅读全文
posted @ 2020-03-15 18:31
Jinxiaobo0509
阅读(141)
评论(0)
推荐(0)
摘要:
1 // 312/313 始终会出现一种情况——>全0 2 3 // 后来引进了双指针算法 4 class Solution 5 { 6 public: 7 vector<vector<int>> threeSum(vector<int>& nums) 8 { 9 vector<vector<int 阅读全文
posted @ 2020-03-15 18:29
Jinxiaobo0509
阅读(106)
评论(0)
推荐(0)
摘要:
1 class Solution 2 { 3 public: 4 string longestCommonPrefix(vector<string>& strs) 5 { 6 string res; 7 if(strs.empty()) return res; 8 int min_length = 阅读全文
posted @ 2020-03-15 18:26
Jinxiaobo0509
阅读(129)
评论(0)
推荐(0)
摘要:
1 class Solution 2 { 3 private: 4 unordered_map<string,int> hash = {{"I",1},{"IV",4},{"V",5},{"IX",9},{"X",10}, 5 {"XL",40},{"L",50},{"XC",90},{"C",10 阅读全文
posted @ 2020-03-15 18:25
Jinxiaobo0509
阅读(109)
评论(0)
推荐(0)
摘要:
1 //用到了贪心思想 2 class Solution 3 { 4 public: 5 int a[13] = {1,4,5,9,10,40,50,90,100,400,500,900,1000}; 6 string b[13] = {"I","IV","V","IX","X","XL","L", 阅读全文
posted @ 2020-03-15 18:23
Jinxiaobo0509
阅读(175)
评论(0)
推荐(0)
摘要:
1 //双指针算法 2 class Solution 3 { 4 public: 5 int maxArea(vector<int>& height) 6 { 7 int n = height.size(); 8 int Area = 0; 9 int l = 0,r = n - 1; 10 whi 阅读全文
posted @ 2020-03-15 18:22
Jinxiaobo0509
阅读(87)
评论(0)
推荐(0)
摘要:
1 class Solution 2 { 3 public: 4 bool isPalindrome(int x) 5 { 6 if(x < 0) return false; 7 vector<int> nums; 8 while(x) 9 { 10 nums.push_back(x % 10); 阅读全文
posted @ 2020-03-15 18:20
Jinxiaobo0509
阅读(98)
评论(0)
推荐(0)
摘要:
1 class Solution 2 { 3 public: 4 int myAtoi(string str) 5 { 6 long long res = 0; 7 bool flag = true; 8 bool jisuan = false; 9 for(int i = 0;i < str.si 阅读全文
posted @ 2020-03-15 18:17
Jinxiaobo0509
阅读(133)
评论(0)
推荐(0)
摘要:
1 //注意x = abs(x) x->[-2147483648,2147483647] 2 class Solution 3 { 4 public: 5 int reverse(int x) 6 { 7 bool f = false; 8 long long res = 0; 9 if(x < 0 阅读全文
posted @ 2020-03-15 18:16
Jinxiaobo0509
阅读(133)
评论(0)
推荐(0)
摘要:
1 //找规律题 等差数列 2m-2 2 class Solution 3 { 4 public: 5 string convert(string s, int m) 6 { 7 if(m == 1) return s; 8 int n = s.size(); 9 string res; 10 fo 阅读全文
posted @ 2020-03-15 18:14
Jinxiaobo0509
阅读(128)
评论(0)
推荐(0)

浙公网安备 33010602011771号