淘先锋技术网

首页 1 2 3 4 5 6 7

3. 无重复字符的最长子串

class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        res = 0
        visited = list()
        # 先左移后右移窗口
        for i in range(len(s)):
            # 左移窗口
            while s[i] in visited: visited.pop(0)
            # 右移窗口
            visited.append(s[i])
            res = max(res, len(visited))
        return res

206. 反转链表

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def reverseList(self, head: ListNode) -> ListNode:
        pre, cur = None, head
        while cur:
            # 存储当前链表的下一个节点为临