双指针
qq_45692660
这个作者很懒,什么都没留下…
展开
-
双指针-88(合并两个有序链表)-28-925
class Solution(object): def merge(self, nums1, m, nums2, n): """ :type nums1: List[int] :type m: int :type nums2: List[int] :type n: int :rtype: None Do not return anything, modify nums1 in-place instea..原创 2021-05-05 11:27:29 · 71 阅读 · 0 评论 -
双指针-167-350-26-345-141
class Solution(object): def twoSum(self, numbers, target): """ :type numbers: List[int] :type target: int :rtype: List[int] """ left=0 right=len(numbers)-1 while left<right: .原创 2021-05-04 22:38:27 · 112 阅读 · 0 评论 -
双指针-剑指offer22-349-977-1800-283-27
# Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# self.val = x# self.next = Noneclass Solution(object): def kthToLast(self, head, k): """ :type head: ListNode :type.原创 2021-05-02 22:41:28 · 124 阅读 · 0 评论 -
881-双指针-救生艇数量
1.排序+双指针class Solution(object): def numRescueBoats(self, people, limit): """ :type people: List[int] :type limit: int :rtype: int """ people.sort() f_point=0 l_point=len(people)-1 .原创 2021-01-04 20:07:48 · 81 阅读 · 0 评论 -
哈希表-双指针-141-环形链表
1.哈希表# Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# self.val = x# self.next = Noneclass Solution(object): def hasCycle(self, head): """ :type head: ListNode :rt.原创 2020-12-30 21:03:46 · 92 阅读 · 0 评论 -
双指针-哈希表-17.11-单词距离
1.哈希表class Solution(object): def findClosest(self, words, word1, word2): """ :type words: List[str] :type word1: str :type word2: str :rtype: int """ l=len(words) hasp_map={} for.原创 2020-12-23 21:06:51 · 87 阅读 · 0 评论 -
双指针-349-数组的交集
1.哈希表class Solution(object): def intersection(self, nums1, nums2): """ :type nums1: List[int] :type nums2: List[int] :rtype: List[int] """ hasp_map={} for i in range(len(nums1)): if .原创 2020-12-22 21:37:00 · 66 阅读 · 0 评论 -
双指针-977-有序数组的平方
1.暴力法:class Solution(object): def sortedSquares(self, nums): """ :type nums: List[int] :rtype: List[int] """ for i in range(len(nums)): nums[i]*=nums[i] nums.sort() return nums2.双指.原创 2020-12-22 21:00:02 · 113 阅读 · 0 评论 -
双指针-344-反转字符串
class Solution(object): def reverseString(self, s): """ :type s: List[str] :rtype: None Do not return anything, modify s in-place instead. """ ''' all_data=len(s) for i in range.原创 2020-12-21 21:44:50 · 117 阅读 · 0 评论 -
双指针-22/面试题0202-链表中倒数第k个节点
1.暴力法:时间复杂度:O(N) 空间复杂度:O(N)# Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# self.val = x# self.next = Noneclass Solution(object): def getKthFromEnd(self, head, k): """ :.原创 2020-12-21 21:14:50 · 95 阅读 · 0 评论 -
数组-283-移动零
1.排序false,true的顺序进行排序class Solution(object): def moveZeroes(self, nums): """ :type nums: List[int] :rtype: None Do not return anything, modify nums in-place instead. """ nums.sort(key=lambda x:x==0)2.先找出不为0的.原创 2020-12-20 19:52:18 · 104 阅读 · 0 评论