已结束
https://leetcode.cn/problems/remove-duplicates-from-sorted-array/solution/kuai-man-zhi-zhen-dui-shu-zu-qu-zhong-by-p7go/ https://leetcode.cn/problems/remove-duplicates-from-sorted-list/solution/kuai-man-zhi-zhen-shan-chu-lian-biao-zho-f4uk/
https://leetcode.cn/problems/remove-element/solution/man-zhi-zhen-dang-jian-die-by-qq54045354-0ztu/ https://leetcode.cn/problems/minimum-window-substring/solutions/2372068/hua-dong-chuang-kou-jie-jue-zui-xiao-fu-0aub4/
https://leetcode.cn/problems/permutation-in-string/solutions/2374589/chuang-kou-jian-cha-shi-fou-bao-han-zi-c-pykn/ https://leetcode.cn/problems/find-all-anagrams-in-a-string/solutions/2374641/hua-dong-chuang-kou-cha-zhao-zi-mu-yi-we-j13m/ https://leetcode.cn/problems/longest-substring-without-repeating-characters/solutions/2374696/kuo-da-suo-xiao-chuang-kou-cha-zhao-wu-z-v0ok/ https://leetcode.cn/problems/binary-search/solutions/2374783/ji-chu-er-fen-cha-zhao-by-kenanhuang99-y5o8/ https://leetcode.cn/problems/longest-palindromic-substring/solutions/2374826/zuo-you-zhi-zhen-cong-zhong-xin-xiang-li-4pc1/
https://leetcode.com/problems/longest-palindromic-substring/solutions/3849782/longestpalindrome/ https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/solutions/3849948/removeduplicates/
https://leetcode.cn/problems/two-sum-ii-input-array-is-sorted/solutions/2368828/zuo-you-zhi-zhen-qiu-twosumde-wen-ti-by-0zc07/
https://leetcode.com/problems/longest-palindromic-substring/solutions/3850226/python-two-pointers-solution/
https://leetcode.com/problems/remove-duplicates-from-sorted-array/solutions/3850375/remove-duplicates-from-sorted-array-in-java/
Q26: https://leetcode.com/problems/remove-duplicates-from-sorted-array/solutions/3850402/two-pointers/
Two Sum Hashtable 解法:enumerate遍历数组,返回索引和value看一下差值是否在hash表里,在的话返回这两个成和值的索引 i和 hash[diff],没有的话存储key和val,继续下一个. 复杂度 O(n)
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
hashmap = {}
for i, n in enumerate(nums):
diff = target - n
if diff in hashmap:
return i, hashmap[diff]
hashmap[n] = i
双指针做法 统一Two sum 数组没有排序,并且需要返回原始索引, 所以先用range分配从0递增的index,后和nums zip在一起,类似SQL中window function的 row_number() OVER(), 这样保持了原索引之后再进行排序,value是递增的,但是index是原来的。
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
left, right = 0, len(nums)-1
nums = sorted(zip(nums, range(len(nums))))
while left < right:
if nums[left][0] + nums[right][0] == target:
return [nums[left][1], nums[right][1]]
elif nums[left][0] + nums[right][0] > target:
right -= 1
else:
left += 1
return []
Two Sum 2 数组已经排序,并且返回的索引是基于当前数组的,并且从1开始。 因为是排序过的 小于则增大left,大于则减小right,返回的是下标,所以index要+1
class Solution:
def twoSum(self, numbers: List[int], target: int) -> List[int]:
left = 0
right = len(numbers)-1
while left <= right:
total = numbers[left] + numbers[right]
if total == target:
return left+1, right+1
elif total <= target:
left +=1
else:
right -=1
return []
https://leetcode.cn/problems/two-sum/solutions/2368886/shuang-zhi-zhen-two-sum-he-two-sum2dui-b-037q/
https://leetcode.cn/problems/remove-duplicates-from-sorted-array/solutions/2368980/kuai-man-zhi-zhen-by-2ba4zmutle-ram9/
26: https://leetcode.cn/problems/remove-duplicates-from-sorted-array/solutions/2380262/cppshuang-zhi-zhen-0802-26-shan-chu-you-4cxyu/
https://leetcode.com/problems/longest-palindromic-substring/solutions/3850899/two-pointers-longest-palindromic-substring/
https://leetcode.com/problems/remove-duplicates-from-sorted-array/solutions/3850929/26-remove-duplicates-from-sorted-array/
删除有序数组中的重复项 https://leetcode.cn/problems/remove-duplicates-from-sorted-array/solutions/2369037/shan-chu-you-xu-shu-zu-zhong-de-zhong-fu-d7m3/ 移除元素 https://leetcode.cn/problems/remove-element/solutions/2369093/yi-chu-yuan-su-by-gei-wei-lai-de-zi-ji-i-yngp/ 两数之和 II - 输入有序数组 https://leetcode.cn/problems/two-sum-ii-input-array-is-sorted/solutions/2369220/liang-shu-zhi-he-ii-shu-ru-you-xu-shu-zu-4lx3/
https://leetcode.cn/problems/two-sum-ii-input-array-is-sorted/solutions/2369366/problem-167-liang-shu-zhi-he-ii-shu-ru-y-z8iy/ https://leetcode.cn/problems/remove-duplicates-from-sorted-array/solutions/2369384/problem-26-shan-chu-you-xu-shu-zu-zhong-z2ek5/
https://leetcode.com/problems/remove-duplicates-from-sorted-array/solutions/3850927/slow-fast-pointers/ https://leetcode.com/problems/reverse-string/solutions/3850942/track-front-end-together/ https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/solutions/3851034/sliding-windows/
[5. Longest Palindromic Substring] https://leetcode.com/problems/longest-palindromic-substring/solutions/3851163/two-pointers/
删除有序数组中的重复项: https://leetcode.cn/problems/remove-duplicates-from-sorted-array/solutions/2369281/shan-chu-you-xu-shu-zu-zhong-de-zhong-fu-c7kn/ 删除排序链表中的重复元素 https://leetcode.cn/problems/remove-duplicates-from-sorted-list/solutions/2369482/shan-chu-pai-xu-lian-biao-zhong-de-zhong-n108/ 删除排序链表中的重复元素v https://leetcode.cn/problems/remove-element/solutions/2369521/shan-chu-pai-xu-lian-biao-zhong-de-zhong-y5tm/ 两数之和 II - 输入有序数组 https://leetcode.cn/problems/two-sum-ii-input-array-is-sorted/solutions/2369712/liang-shu-zhi-he-ii-shu-ru-you-xu-shu-zu-v1c0/ 反转字符串 https://leetcode.cn/problems/reverse-string/solutions/2369741/fan-zhuan-zi-fu-chuan-by-guabigwind-1mur/ 最长回文子串 https://leetcode.cn/problems/longest-palindromic-substring/solutions/2369871/zui-chang-hui-wen-zi-chuan-by-guabigwind-m947/
Q26. Remove Duplicates from Sorted Array https://leetcode.com/problems/remove-duplicates-from-sorted-array/discuss/3849260/Java-one-pass-solution
Q83. Remove Duplicates from Sorted List https://leetcode.com/problems/remove-duplicates-from-sorted-list/discuss/3849410/Java-slow-fast-pointer
Q27. Remove Element https://leetcode.com/problems/remove-element/discuss/3849880/Java-slow-fast-pointer-solution
Q283. Move Zeroes https://leetcode.com/problems/move-zeroes/discuss/3849939/Java-fast-slow-pointer-solution
Q167. Two Sum II - Input Array Is Sorted https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/discuss/3850295/Java-two-pointer-solution
Q344. Reverse String https://leetcode.com/problems/reverse-string/discuss/3850305/Java-two-pointer-solution
Q5. Longest Palindromic Substring https://leetcode.com/problems/longest-palindromic-substring/discuss/3850356/Java-Intuitive-Solution
Q26. 删除有序数组中的重复项 https://leetcode.cn/problems/remove-duplicates-from-sorted-array/solutions/2369465/shan-chu-you-xu-shu-zu-zhong-de-zhong-fu-5cn3/
https://leetcode.cn/problems/two-sum-ii-input-array-is-sorted/solutions/2369526/shuang-zhi-zhen-by-alank-usyd-1lpr/