标签: 双指针

2 篇文章

3.无重复字符的最长子串
原题链接:3. 无重复字符的最长子串 - 力扣(LeetCode) 思路:暴力至少是O(n^2),对于子串问题,可以采用双指针,滑动窗口等方法 class Solution { public int lengthOfLongestSubstring(String s) { //map记录的是对应字符,最近出现的下标 HashMap<Chara…
42.接雨水
原题链接:42. 接雨水 - 力扣(LeetCode) 双指针优化思路: class Solution { public int trap(int[] height) { int n = height.length; //纪录某个节点左右最高的高度 int[] lHeight = new int[n]; int[] …