![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Two Pointer
文章平均质量分 57
再见小小ronnie
这个作者很懒,什么都没留下…
展开
-
Leetcode 15. 3Sum
/** * First sort the array, (i) * scan through the array, set every -nums[i] as a target, (ii) * for the rest elements i+1<=i<=n do a two-pointer two sum原创 2017-01-02 06:26:56 · 154 阅读 · 0 评论 -
Leetocde 215. Kth Largest Element in an Array
class Solution { public int kthLargestElement(int k, int[] nums) { int target = nums.length - k; int i = 0, lo = 0, hi = nums.length-1; while (true) {原创 2017-02-23 10:11:23 · 233 阅读 · 0 评论 -
Leetcode 344. Reverse String
public class Solution { public String reverseString(String s) { StringBuilder sb = new StringBuilder(s); int low = 0, high = s.length()-1; while (low < high) {原创 2017-01-27 12:21:22 · 141 阅读 · 0 评论 -
Leetcode 345. Reverse Vowels of a String
public class Solution { public String reverseVowels(String s) { HashSet hs = new HashSet<>(); hs.add('a'); hs.add('e'); hs.add('i'); hs.add('o'); hs原创 2017-01-27 12:14:50 · 134 阅读 · 0 评论 -
Leetcode 141. Linked List Cycle
Two pointers, one is slow and the other is fast. Note that the stop condition is fast.next != null && fast.next.next != null public class Solution { public boolean hasCycle(ListNode head) {原创 2017-01-27 06:22:40 · 164 阅读 · 0 评论 -
Leetcode 438. Find All Anagrams in a String
O(t.length() * s.length()) public class Solution { public List findAnagrams(String s, String p) { List list = new ArrayList<>(); // create an array to save the counts for原创 2017-01-12 13:31:26 · 294 阅读 · 0 评论 -
Leetcode 31. Next Permutation
/** * e.g. 1 2 3 4 * Step i. From right to left, find the first element at index i which breaks the ascending order, * if no such i exists, then the array is sorted as ascending order, return the原创 2017-01-03 09:41:17 · 156 阅读 · 0 评论 -
Leetcode 18. 4Sum
public class Solution { // two-pointer to search three numbers sum to target public static void threeSum(List> res, int start, int goal, int target, int[] nums) { for (int i=start; i<n原创 2017-01-02 11:26:39 · 202 阅读 · 0 评论 -
Leetcode 16. 3Sum Closest
/** * Similar with 3sum. * Difference is target now becomes -(nums[i]-1), a * and also need a variable diff to save the closest distance * between triplets and targets. */ public class Solution原创 2017-01-02 07:07:27 · 160 阅读 · 0 评论 -
Leetcode 125. Valid Palindrome
/** * Character methods. * isLetter(), isDigit(), isLetterOrDigit() * First check if characters are alphanumberic, * then check if characters are equal. */ public class Solution { public boo原创 2017-01-29 07:37:53 · 173 阅读 · 0 评论