![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
双指针
hmyqwe
这个作者很懒,什么都没留下…
展开
-
leetcode-283-移动零
class Solution { public void moveZeroes(int[] nums) { // 初始化快慢指针 int fast = 0; int slow = 0; // 得到不包含 0 的新数组,长度为 slow while (fast < nums.length) { if (nums[fast] != 0) { nums[slow].原创 2021-04-21 11:18:17 · 47 阅读 · 0 评论 -
leetcode-27-移除元素
class Solution { public int removeElement(int[] nums, int val) { if (nums.length == 0) { return 0; } // 初始化快慢指针 int fast = 0; int slow = 0; while (fast < nums.length) { if (nu..原创 2021-04-21 10:54:55 · 62 阅读 · 0 评论 -
leetcode-83-删除排序链表中的重复元素
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = next; } * ..原创 2021-04-21 10:25:10 · 49 阅读 · 0 评论 -
leetcode-26-删除有序数组中的重复项
class Solution { public int removeDuplicates(int[] nums) { if (nums.length == 0) { return 0; } // 初始化快慢指针 int slow = 0; int fast = 0; while (fast < nums.length) { if (nums[fas..原创 2021-04-21 10:11:27 · 63 阅读 · 0 评论 -
leetcode-3-无重复字符的最长子串
class Solution { public int lengthOfLongestSubstring(String s) { HashMap<Character, Integer> window = new HashMap<>(); int left = 0; int right = 0; int ans = 0; while(right < s.length()) { .原创 2021-04-13 15:46:02 · 43 阅读 · 0 评论 -
leetcode-438-找到字符串中所有字母异位词
class Solution { public List<Integer> findAnagrams(String s, String p) { HashMap<Character, Integer> need = new HashMap<>(); HashMap<Character, Integer> window = new HashMap<>(); for(c.原创 2021-04-13 08:55:48 · 68 阅读 · 0 评论 -
leetcode-567-字符串的排列
class Solution { public boolean checkInclusion(String s1, String s2) { HashMap<Character, Integer> need = new HashMap<>(); HashMap<Character, Integer> window = new HashMap<>(); for(char c : s1.t.原创 2021-04-12 17:49:50 · 60 阅读 · 0 评论 -
滑动窗口算法模板
滑动窗口算法模板 public void slidWindow(String s, String t) { HashMap<Character, Integer> need = new HashMap<>(); HashMap<Character, Integer> window = new HashMap<>(); for(char c : t.toCharArray()) {原创 2021-04-12 17:07:35 · 229 阅读 · 0 评论 -
leetcode-76-最小覆盖子串
class Solution { public String minWindow(String s, String t) { HashMap<Character, Integer> need = new HashMap<Character, Integer>(); HashMap<Character, Integer> window = new HashMap<Character, Integer>(); .原创 2021-04-12 17:00:56 · 73 阅读 · 0 评论 -
leetcode-344-反转字符串
class Solution { public void reverseString(char[] s) { int left = 0; int right = s.length - 1; while (left < right) { // 首尾交换 char temp = s[left]; s[left] = s[right]; s[right].原创 2021-04-09 11:30:55 · 56 阅读 · 0 评论 -
leetcode-167-两数之和 II - 输入有序数组
class Solution { public int[] twoSum(int[] numbers, int target) { int left = 0, right = numbers.length - 1; while (left <= right) { int sum = numbers[left] + numbers[right]; if (sum == target) { .原创 2021-04-09 10:39:08 · 52 阅读 · 0 评论 -
leetcode-19-删除链表的倒数第 N 个结点
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = next; } * ..原创 2021-04-08 17:58:38 · 44 阅读 · 0 评论 -
leetcode-876-链表的中间结点
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ class Solution { public ListNode middleNode(ListNode head) { ListNode fast; ListNod.原创 2021-04-08 11:16:40 · 37 阅读 · 0 评论 -
leetcode-142-环形链表 II
/** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */ public class Solution { public ListNode detectCycle(ListNode he..原创 2021-04-08 11:06:44 · 43 阅读 · 0 评论 -
leetcode-141-环形链表
/** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */ public class Solution { public boolean hasCycle(ListNode head) ..原创 2021-04-08 10:38:01 · 43 阅读 · 0 评论