[Python] COUNTIF
- 2023.09.10
- Python
sum(1 for ... in ... if ...) or sum(1 if ... else 0 for ... in ...)
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 ...
Problem https://leetcode.com/contest/weekly-contest-361/problems/minimum-operations-to-make-a-special-number/ Solution Time Complexity: O(len(num)) Space Complexity: O(1) (The input and output general ...
Problem https://leetcode.com/contest/weekly-contest-361/problems/count-symmetric-integers/ Solution 三位數(ex: 0303)不算 Time Complexity: O(1) Space Complexity: O(1) (The input and output generally do not ...
Problem https://leetcode.com/problems/permutation-in-string Solution: Sliding Window First Solution Time Complexity: O(len(s2)) Space Complexity: O(26) ≡ O(1) (The input and output generally do not co ...