随笔分类 - 2 pointers
摘要:每次移动3个pointer 里面最小的那个就好了。记录整个过程找最近的3个数。3个数之中median没意义,距离主要由最小和最大决定。基本就是这个思路。很快编完就过了编程阶段。
阅读全文
摘要:This is a follow up of Shortest Word Distance. The only difference is now word1 could be the same as word2. Given a list of words and two words word1
阅读全文
摘要:Given a list of words and two words word1 and word2, return the shortest distance between these two words in the list. For example,Assume that words =
阅读全文
摘要:Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two ...
阅读全文
摘要:Problem: Given a string, find the lexicographical minimum string keeping the order of alphabets same as the original string.For example: Solution: Thi
阅读全文
摘要:sorted 数组, 常用二指针遍历, 会倒叙, 会前序 逆序遍历的好处, 1只遍历后面的 2此题在于空间上可以不干扰.
阅读全文
摘要:两个数组两个指针 两个数组的题常sort, 再通过两指针遍历 常常与0 的差的正负来判断, 来判断指针的走位, 此处直接判断大小更方便
阅读全文
摘要:其实是一种特别顺序的排序, 所以就用quicksort-partition, 不过比较的元素和设计互相patition, partition 的比较因为是有equals的, 所以得用三个指针遍历 考点: partition 的设计, pivot 的选择 , 另一方的排序通过nuts排好后的数组再排,
阅读全文
摘要:数组常sort
阅读全文
摘要:一维数组解题的三种方法: 双指针\ 队列 栈 堆\ 动归\二分法\hashmap Partition 题—以quicksort 为模板--O(n) 出题点: 如何Patition ? 二分递归的部分 前向型指针 – O(n) 窗口类指针常用到的数据结构是 int sum, hashmap, hash
阅读全文
摘要:道题给定我们一个有序数组,让我们总结区间,具体来说就是让我们找出连续的序列,然后首尾两个数字之间用个“->"来连接,那么我只需遍历一遍数组即可,每次检查下一个数是不是递增的,如果是,则继续往下遍历,如果不是了,我们还要判断此时是一个数还是一个序列,一个数直接存入结果,序列的话要存入首尾数字和箭头“-
阅读全文
摘要:carry sum 处理字符串的运算问题, 在转化成数值: (int) (num1.charAt(i) - '0') 转换成数值(同 Character.getNumericValue(char a) ), 非ASCII 码. 再 转化成字符. 也常转化成AScII 码, 在转换成字符串, 所以看看
阅读全文
摘要:Given a nested list of integers represented as a string, implement a parser to deserialize it. Each element is either an integer, or a list -- whose e
阅读全文
摘要:https://leetcode.com/problems/reverse-vowels-of-a-string/#/description http://www.cnblogs.com/EdwardLiu/p/6096319.html
阅读全文
摘要:https://leetcode.com/problems/4sum/#/solutions Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target
阅读全文
摘要:Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers.
阅读全文
摘要:为何不像76. Minimum Window Substring用数组来匹配, 是因为双指针是根据字符串的顺序遍历的, 而数组的话没有顺序.如 For example,S = "ADOBECODEBANC"T = "ABC" Minimum window is "BANC". 并不是非得ABC的顺序
阅读全文

浙公网安备 33010602011771号