随笔分类 -  双指针系列

双指针是这样的模式:两个指针朝着左右方向移动(双指针分为同向双指针和异向双指针),直到他们有一个或是两个都满足某种条件。双指针通常用在排好序的数组或是链表中寻找对子。比如,你需要去比较数组中每个元素和其他元素的关系时,你就需要用到双指针了。
904. 水果成篮
摘要:https://leetcode-cn.com/problems/fruit-into-baskets/ 暴力法:超时 func totalFruit(tree []int) int { res := 0 n := len(tree) i,j := 0,0 for i=0;i<n;i++{ pre1 阅读全文

posted @ 2020-05-06 20:16 wsw_seu 阅读(305) 评论(0) 推荐(0) 编辑

1248. 统计「优美子数组」
摘要:https://leetcode-cn.com/problems/count-number-of-nice-subarrays/ func numberOfSubarrays(nums []int, k int) int { //滑动窗口法:left 每次滑动到下一个奇数处,并记下滑动的距离;rig 阅读全文

posted @ 2020-04-23 22:53 wsw_seu 阅读(187) 评论(0) 推荐(0) 编辑

导航

< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8
点击右上角即可分享
微信分享提示