Leetcode
记录学习
Murasame_oO
这个作者很懒,什么都没留下…
展开
-
Leetcode学习8
反转链表206 反转链表/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ListNode(int x, ListNode *next) : val(原创 2022-03-07 17:28:41 · 441 阅读 · 0 评论 -
Leetcode学习7
21.合并两个有序链表原创 2022-03-07 14:15:23 · 619 阅读 · 0 评论 -
Leetcode学习6
20 有效的括号class Solution {public: bool isValid(string s) { stack<char> stk; int n=s.size(); for(int i=0;i<n;i++) { if(s[i]=='{'||s[i]=='['||s[i]=='(') { stk.emplace(s[i]);原创 2022-03-06 16:59:10 · 90 阅读 · 0 评论 -
Leetcode学习5
15.三数之和class Solution {public: vector<vector<int>> threeSum(vector<int>& nums) { vector<vector<int>> res={}; if (nums.size() < 3) { return res; } sort(nums.begin原创 2022-03-05 15:08:59 · 186 阅读 · 0 评论 -
Leetcoode学习4
5.最长回文子串(1) 暴力解法(超时)class Solution {public: bool check(string s) { int i=0,j=s.size()-1; while(i<s.size()/2) { if(s[i]!=s[j]) { return false; } i++;原创 2022-03-02 23:29:33 · 307 阅读 · 0 评论 -
Leetcode学习3
3.无重复字符的最长字串class Solution {public: int lengthOfLongestSubstring(string s) { unordered_map<char,int> note; int i=0,j=0,max=0; while(i<s.size()&&j<s.size()) { if(note.count(s[j])>0) //原创 2022-01-31 02:06:02 · 2798 阅读 · 0 评论 -
Leetcode学习2
2.两数相加自己写的堆溢出了。。。接下来就 看 答 案/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ListNode(int x, ListNo原创 2022-01-31 01:06:54 · 836 阅读 · 0 评论 -
Leetcode学习1
1.两数之和第一想法:排序后,设置头尾俩指针。指针所指两数之和大于target时,尾指针前移;指针所指两数之和小于target时,头指针后移。然而题目要求返回原先的顺序,故不可。//错误代码class Solution {public: vector<int> twoSum(vector<int>& nums, int target) { vector<int> copy=nums; sort(nums.begin(原创 2022-01-29 20:28:53 · 690 阅读 · 0 评论