Problem https://leetcode.com/problems/find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree Solution: DFS n := number of nodes in the original tree Time Complexity: O(n) Space Complexity: ...
Problem https://leetcode.com/problems/kth-ancestor-of-a-tree-node First Solution: Binary Lifting [Time Limit Exceeded 8 / 17 testcases passed] Time Complexity: O(n ** 2) __init__(): worst case – ...
Problem https://leetcode.com/contest/weekly-contest-361/problems/minimum-edge-weight-equilibrium-queries-in-a-tree/ There is an undirected tree with n nodes labeled from 0 to n – 1. You are give ...
sum(1 for ... in ... if ...) or sum(1 if ... else 0 for ... in ...)
Problem https://leetcode.com/contest/weekly-contest-361/problems/count-of-interesting-subarrays/ 相關例題 Leetcode # 974. ⭐️ Subarray Sums Divisible by K Solution: Dynamic Programming [Time Limit Exceeded ...
Problem https://leetcode.com/problems/subarray-sums-divisible-by-k Solution 令 nums[i] = [4, 5, 0, -2, -3, 1], k = 5 能夠被k整除的子字串有: [5], [0], [5, 0], [-2, -3], [0, -2, -3], [5, 0, -2, -3], [4, 5, 0, -2, ...
Problem https://leetcode.com/contest/weekly-contest-362/problems/minimum-moves-to-spread-stones-over-grid/ Solution z := len([True for row in grid for num in row if num == 0]) Time Complexity: O(z!) S ...
Problem https://leetcode.com/contest/weekly-contest-362/problems/determine-if-a-cell-is-reachable-at-a-given-time/ Testcases # Input Expected 1 1 1 1 1 3 True 2 1 2 1 2 1 False 3 1 3 1 3 0 True 4 1 1 ...
Problem https://leetcode.com/contest/weekly-contest-362/problems/points-that-intersect-with-cars/ 相關例題 Leetcode # 56. ⭐️ Merge Intervals Solution Time Complexity: O(len(nums)) Space Complexity: O(1) ( ...
Problem https://leetcode.com/problems/merge-intervals Solution Time Complexity: O(len(intervals)) Space Complexity: O(1) (The input and output generally do not count towards the space complexity.) cla ...