Home

Alert Using Same Key-Card Three or More Times in a One Hour Period

1604. Alert Using Same Key-Card Three or More Times in a One Hour Period LeetCode company workers use key-cards to unlock office doors. Each time a worker uses their key-card, the security system saves the worker’s name and the time when it was used. The system emits an alert if any worker uses the key-card three or more times in a one-hour peri...

Read more

4Sum II

454. 4Sum II Solution Get 2Sum first and then combine the 2 2Sums. We only need to get one 2Sum, and get its negation from the other 2 arrays. def fourSumCount(self, A, B, C, D): """ :type A: List[int] :type B: List[int] :type C: List[int] :type D: List[int] :rtype: int """ dic = collections...

Read more

Throne Inheritance

1600. Throne Inheritance Solution def __init__(self, kingName): """ :type kingName: str """ self.king = kingName self.relation = collections.defaultdict(list) self.parent = {kingName: None} self.deadp = set() def birth(self, parentName, childName): """ :type parentName: str :type childName: str :rtype...

Read more

Maximum Profit of Operating a Centennial Wheel

1599. Maximum Profit of Operating a Centennial Wheel You are the operator of a Centennial Wheel that has four gondolas, and each gondola has room for up to four people. You have the ability to rotate the gondolas counterclockwise, which costs you runningCost dollars. You are given an array customers of length n where customers[i] is the number...

Read more

Maximum Number of Achievable Transfer Requests

1601. Maximum Number of Achievable Transfer Requests We have n buildings numbered from 0 to n - 1. Each building has a number of employees. It’s transfer season, and some employees want to change the building they reside in. You are given an array requests where requests[i] = [fromi, toi] represents an employee’s request to transfer from buildi...

Read more

Crawler Log Folder

1598. Crawler Log Folder The Leetcode file system keeps a log each time some user performs a change folder operation. The operations are described below: ”../” : Move to the parent folder of the current folder. (If you are already in the main folder, remain in the same folder). “./” : Remain in the same folder. “x/” : Move to the child folder...

Read more

Game of Life

289. Game of Life Solution Reference We need to come out with an idea of keeping the current state and the next state in the matrix at the same time. Use bits: [2nd bit, 1st bit] = [next state, current state] To get the current state: board[i][j] & 1 To get the next state: board[i][j] >> 1 def...

Read more

Delete Node in a Linked List

237. Delete Node in a Linked List Solution Copy the next node’s val to next.next node Move the pointer def deleteNode(self, node): """ :type node: ListNode :rtype: void Do not return anything, modify node in-place instead. """ node.val = node.next.val node.next = node.next.next

Read more