视频讲解
代码
class Solution
# construct a double linked list node class
class DoubleLinkedListNode:
def __init__(self, val):
self.val = val
self.prev = None
self.next = None
# step-1: construct the circular double linked list
head = DoubleLinkedListNode(1)
curr = head
for i in range(2,n+1):
new_curr = DoubleLinkedListNode(i)
new_curr.prev = curr
curr.next = new_curr
curr = new_curr
curr.next = head
head.prev = curr
# step-2: do the loop ( check if the size is 1, if not, find the k-th element and delete)
curr = head
while curr.next != curr:
for _ in range(k-1):
curr = curr.next
curr.prev.next = curr.next
curr.next.prev = curr.prev
curr = curr.next
# step-3: return the result
return curr.val
PPT讲解
本题涉及的知识点:
我的 Leetcode 讲解频道
代码链接
面试高频考点Youtube链接
- 数组(Array)
- 哈希表(Hash Table)
- 链表(Linked List)
- 数学(Math)
- 链表(Linked List)
- 双指针(Two Pointers)
- 字符串(String)
- 二分查找(Binary Search)
- 分治(Divide and Conquer)
- 动态规划(Dynamic Programming)
- 回溯(Backtracking)
- 栈(Stack)
- 堆(Heap)
- 贪心算法(Greedy)
- 排序(Sort)
- 树(Tree)
- 深度优先搜索(Depth-First Search)
- 广度优先搜索(Breadth-First Search)
- 二叉查找树(Binary Search Tree)
- 递归(Recursion)
- 队列(Queue)
- 移动窗口(Sliding Window)