摘要:法一: class Solution: def hasCycle(self, head: ListNode) -> bool: a = set() while head: if head in a: return True a.add(head) head = head.next return Fa
阅读全文
摘要:# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None 法一: class Solution: def mergeTwoList
阅读全文
摘要:法一:# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def removeNthFrom
阅读全文
摘要:class Solution: def convert(self, s: str, numRows: int) -> str: if numRows < 2: return s res = ["" for _ in range(numRows)] i, flag = 0, -1 for c in s
阅读全文
摘要:class Solution(object): def threeSum(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ nums.sort() if not nums or len(nums)<3: return
阅读全文
摘要:法一: class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: ret = [] for i in range(len(nums)): for j in range(1,len(nums)-i): if
阅读全文
摘要:法一: class Solution: def plusOne(self, digits: List[int]) -> List[int]: length = len(digits) res = 0 for i in digits: if digits[-1]!=9: if length!=1: r
阅读全文
摘要:法一: class Solution: def removeElement(self, nums: List[int], val: int) -> int: for i in range(len(nums)-1, -1, -1): if(nums[i] == val): nums.pop(i) re
阅读全文
摘要:法一: class Solution: def rotate(self, nums: List[int], k: int) -> None: """ Do not return anything, modify nums in-place instead. """ n = len(nums) k %
阅读全文