摘要: 长按键入 class Solution { public: bool isLongPressedName(string name, string typed) { int p1 = 0; int p2 = 0; int len1 = name.length(); int len2 = typed.l 阅读全文
posted @ 2020-11-27 13:53 yoyoyayababy 阅读(49) 评论(0) 推荐(0) 编辑
摘要: 队列和栈 循环队列 class MyCircularQueue { public: int q[1005]; int left; int right; int size; int ccount; /** Initialize your data structure here. Set the siz 阅读全文
posted @ 2020-10-15 21:37 yoyoyayababy 阅读(94) 评论(0) 推荐(0) 编辑
摘要: 初级算法合集 缺失的数字 class Solution { public: int missingNumber(vector<int>& nums) { int n = nums.size(); int sum = n*(n+1)/2; for(int i=0;i<nums.size();i++) 阅读全文
posted @ 2020-10-13 12:35 yoyoyayababy 阅读(83) 评论(0) 推荐(0) 编辑
摘要: 【leetcode】环形链表2 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * 阅读全文
posted @ 2020-10-11 16:15 yoyoyayababy 阅读(105) 评论(0) 推荐(0) 编辑
摘要: 【leetcode】格雷编码 背下来即可 class Solution { public: vector<int> grayCode(int n) { vector<int> ans; for(int i=0;i<1<<n;i++) { ans.push_back(i^(i>>1)); } retu 阅读全文
posted @ 2020-10-10 02:06 yoyoyayababy 阅读(64) 评论(0) 推荐(0) 编辑
摘要: 【leetcode】最大宽度坡 class Solution { public: int maxWidthRamp(vector<int>& A) { stack<int> ss; int ans = 0; ss.push(0); for(int i=1;i<A.size();i++) { if(A 阅读全文
posted @ 2020-10-09 16:14 yoyoyayababy 阅读(137) 评论(0) 推荐(0) 编辑
摘要: 今天复习单调栈 单调栈:寻找最左边第一个比自己(严格)小/大的数 单调队列:查找滑动窗口中的最值 基本上求滑动窗口的最值就是使用单调队列 【leetcode】min stack 使用两个栈,其中一个保存最小值。 class MinStack { public: /** initialize your 阅读全文
posted @ 2020-10-07 14:30 yoyoyayababy 阅读(85) 评论(0) 推荐(0) 编辑
摘要: 【leetcode】连续整数求和 class Solution { public: int sum1(int k) { return k*(k+1)/2; } int consecutiveNumbersSum(int N) { int ccount = 0; int k=1; while(sum1 阅读全文
posted @ 2020-10-02 20:45 yoyoyayababy 阅读(100) 评论(0) 推荐(0) 编辑
摘要: 2020结束之前,再怎么忙也要写满30天吧。 【leetcode 】two sum1 hashmap class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { map<int,int> hashmap; 阅读全文
posted @ 2020-09-30 10:53 yoyoyayababy 阅读(105) 评论(0) 推荐(0) 编辑
摘要: 【使用labuladong的算法小抄进行复习】 二分查找的思路并不复杂,但是算法实现的细节十分重要,区间是否开闭、大于小于号是否取等,如果没有理解这些细节,每次写二分查找只能靠菩萨保佑才能没有bug。 所有的二分查找基于以下框架 int binarySearch(int[] nums,int[] t 阅读全文
posted @ 2020-09-13 16:26 yoyoyayababy 阅读(162) 评论(0) 推荐(0) 编辑