3 z岁月无声

尚未进行身份认证

暂无相关简介

等级
TA的排名 2w+

LeetCode-30.串联所有单词的子串

地址:https://leetcode-cn.com/problems/substring-with-concatenation-of-all-words/思路:用无序map保留words,遍历字符串s,同时按照words中单词的长度分段处理字符串s,这样可以不必每次清空mapCode:class Solution {public: vector<int> ...

2020-01-14 22:40:21

LeetCode-29.两数相除

地址:https://leetcode-cn.com/problems/divide-two-integers/思路:运用位移运算,由大到小依次判断即可Code:class Solution {public: int divide(int dividend, int divisor) { int INF=((long long)1<<31)-...

2020-01-14 22:35:31

LeetCode-28. 实现 strStr()

地址:https://leetcode-cn.com/problems/implement-strstr/思路:KMP算法Code:class Solution {public: void GetNext(string str,int Next[]){ Next[0]=-1; int k=0; for(int i=1;i&...

2020-01-14 20:32:23

LeetCode-27. 移除元素

地址:https://leetcode-cn.com/problems/remove-element/思路:覆盖操作即可Code:#include<iostream>#include<vector>#include<set>using namespace std;class Solution {public: int rem...

2020-01-07 16:04:36

LeetCode-26. 删除排序数组中的重复项

地址:https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/思路:对于相同的数覆盖掉即可Code:#include<iostream>using namespace std;class Solution {public: int removeDuplicates(vec...

2020-01-07 16:02:44

LeetCode-25. K 个一组翻转链表

地址:https://leetcode-cn.com/problems/reverse-nodes-in-k-group/思路:在翻转时,保存连续的三个节点进行翻转,以及注意翻转区间和两端的连接Code:#include<iostream>#include<algorithm>#include<vector>#include<que...

2020-01-07 16:00:37

LeetCode-24.两两交换链表中的节点

地址:https://leetcode-cn.com/problems/swap-nodes-in-pairs/思路:每次循环记录要交换的两节点和前一个节点,然后做交换即可Code:#include<iostream>#include<algorithm>#include<vector>#include<queue>usin...

2020-01-06 18:57:04

LeetCode-23.合并K个排序链表

地址:https://leetcode-cn.com/problems/merge-k-sorted-lists/思路:一、每次比较k个链表的大小,在取最小的二、利用优先队列可优化每次k个链表的比较Code:#include<iostream>#include<algorithm>#include<vector>#include&lt...

2020-01-06 18:54:53

LeetCode-22.括号生成

地址:https://leetcode-cn.com/problems/generate-parentheses/思路:一、搜索,通过对左括号位置的搜索,最终判断其是否合法即可二、DP,对于dp[n]='('+dp[i]+')'+dp[n-i-1]Code:#include<iostream>#include<algorithm>#include&...

2020-01-06 18:52:21

LeetCode-21. 合并两个有序链表

地址:https://leetcode-cn.com/problems/merge-two-sorted-lists/思路:对两指针依次比较大小即可,注意对于空链表的处理Code:#include<iostream>#include<algorithm>#include<vector>#include<unordered_map&g...

2020-01-05 17:04:01

LeetCode-20. 有效的括号

地址:https://leetcode-cn.com/problems/valid-parentheses/思路:利用栈stack处理Code:#include<iostream>#include<algorithm>#include<vector>#include<stack>#include<unordered_m...

2020-01-05 17:02:16

LeetCode-19. 删除链表的倒数第N个节点

地址:https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/思路:遍历一遍得到链表的长度len,在遍历一遍删除第(len-n+1)节点即可Code:#include<iostream>#include<algorithm>#include<vector>#include&...

2020-01-05 16:59:51

LeetCode-18. 四数之和

地址:https://leetcode-cn.com/problems/4sum/思路:通过遍历中间两个数,再通过两指针从数组两端开始搜索判断,同时注意对重复元素的判断Code:#include<iostream>#include<algorithm>#include<vector>#include<unordered_map&gt...

2020-01-04 17:35:31

LeetCode-17. 电话号码的字母组合

地址:https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/思路:DFS搜索即可Code:#include<iostream>#include<algorithm>#include<vector>#include<unordered_map&gt...

2020-01-04 17:33:22

LeetCode-16. 最接近的三数之和

地址:https://leetcode-cn.com/problems/3sum-closest/思路:一:先排序,再遍历前二个数,在通过二分查找第三个数二:先排序,再遍历中间数,利用两指针从数组两端开始扫描Code:#include<iostream>#include<algorithm>#include<vector>#inclu...

2020-01-04 17:31:54

LeetCode-15. 三数之和

地址:https://leetcode-cn.com/problems/3sum/思路:一、排序后枚举前两个,再二分查找第三个。二、排序后枚举中间元素,再利用两指针从两端扫描,对于重复的三元组,需做处理Code:#include<iostream>#include<algorithm>#include<vector>#include&...

2020-01-03 16:43:13

LeetCode-14. 最长公共前缀

地址:https://leetcode-cn.com/problems/longest-common-prefix/思路:遍历判断即可Code:#include<iostream>#include<algorithm>#include<vector>#include<cmath>#include<map>#in...

2020-01-03 16:38:37

LeetCode-13. 罗马数字转整数

地址:https://leetcode-cn.com/problems/roman-to-integer/思路:用unordered_map存下转换情况,对于4和9的判断,则看s[i+1]的值是否大于s[i]的值即可Code:#include<iostream>#include<algorithm>#include<vector>#inc...

2020-01-03 16:37:26

LeetCode-12. 整数转罗马数字

地址:https://leetcode-cn.com/problems/integer-to-roman/思路:按照题意转换即可Code:#include<iostream>#include<algorithm>#include<vector>#include<cmath>#include<map>#inclu...

2020-01-02 18:09:50

LeetCode-11. 盛最多水的容器

地址:https://leetcode-cn.com/problems/container-with-most-water/思路:一,先将直线(i,ai)按高度由小到大排序,再由大开始遍历ai,同时记录以遍历的直线的下标最值L,R,这样能够保证区间的高度是ai,然后记录与下标最值所形成的区间面积最大值即可 时间复杂度为O(n*log(n))二,博客https://blog.csdn....

2020-01-02 18:07:14

查看更多

勋章 我的勋章
  • 持之以恒
    持之以恒
    授予每个自然月内发布4篇或4篇以上原创或翻译IT博文的用户。不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累!
  • 1024勋章
    1024勋章
    #1024程序员节#活动勋章,当日发布原创博客即可获得
  • 勤写标兵Lv4
    勤写标兵Lv4
    授予每个自然周发布9篇以上(包括9篇)原创IT博文的用户。本勋章将于次周周三上午根据用户上周的博文发布情况由系统自动颁发。