diff --git a/lcci/17.11.Find Closest/README.md b/lcci/17.11.Find Closest/README.md index a95ad6a7b4b98..22b84bc825184 100644 --- a/lcci/17.11.Find Closest/README.md +++ b/lcci/17.11.Find Closest/README.md @@ -31,13 +31,31 @@ ```python class Solution: def findClosest(self, words: List[str], word1: str, word2: str) -> int: - idx1, idx2, ans = 10**5, -10**5, 10**5 - for i, word in enumerate(words): + i, j, ans = 1e5, -1e5, 1e5 + for k, word in enumerate(words): if word == word1: - idx1 = i + i = k elif word == word2: - idx2 = i - ans = min(ans, abs(idx1 - idx2)) + j = k + ans = min(ans, abs(i - j)) + return ans +``` + +```python +class Solution: + def findClosest(self, words: List[str], word1: str, word2: str) -> int: + d = defaultdict(list) + for i, w in enumerate(words): + d[w].append(i) + ans = 1e5 + idx1, idx2 = d[word1], d[word2] + i, j, m, n = 0, 0, len(idx1), len(idx2) + while i < m and j < n: + ans = min(ans, abs(idx1[i] - idx2[j])) + if idx1[i] < idx2[j]: + i += 1 + else: + j += 1 return ans ``` @@ -48,17 +66,39 @@ class Solution: ```java class Solution { public int findClosest(String[] words, String word1, String word2) { - int idx1 = 100000; - int idx2 = -100000; - int ans = 100000; - for (int i = 0; i < words.length; ++i) { - String word = words[i]; + int i = 100000, j = -100000, ans = 100000; + for (int k = 0; k < words.length; ++k) { + String word = words[k]; if (word.equals(word1)) { - idx1 = i; + i = k; } else if (word.equals(word2)) { - idx2 = i; + j = k; + } + ans = Math.min(ans, Math.abs(i - j)); + } + return ans; + } +} +``` + +```java +class Solution { + public int findClosest(String[] words, String word1, String word2) { + Map> d = new HashMap<>(); + for (int i = 0; i < words.length; ++i) { + d.computeIfAbsent(words[i], k -> new ArrayList<>()).add(i); + } + List idx1 = d.get(word1), idx2 = d.get(word2); + int i = 0, j = 0, m = idx1.size(), n = idx2.size(); + int ans = 100000; + while (i < m && j < n) { + int t = Math.abs(idx1.get(i) - idx2.get(j)); + ans = Math.min(ans, t); + if (idx1.get(i) < idx2.get(j)) { + ++i; + } else { + ++j; } - ans = Math.min(ans, Math.abs(idx1 - idx2)); } return ans; } @@ -92,13 +132,34 @@ function findClosest(words: string[], word1: string, word2: string): number { class Solution { public: int findClosest(vector& words, string word1, string word2) { - int idx1 = 1e5, idx2 = -1e5, ans = 1e5; - for (int i = 0; i < words.size(); ++i) + int i = 1e5, j = -1e5, ans = 1e5; + for (int k = 0; k < words.size(); ++k) { - string word = words[i]; - if (word == word1) idx1 = i; - else if (word == word2) idx2 = i; - ans = min(ans, abs(idx1 - idx2)); + string word = words[k]; + if (word == word1) i = k; + else if (word == word2) j = k; + ans = min(ans, abs(i - j)); + } + return ans; + } +}; +``` + +```cpp +class Solution { +public: + int findClosest(vector& words, string word1, string word2) { + unordered_map> d; + for (int i = 0; i < words.size(); ++i) d[words[i]].push_back(i); + vector idx1 = d[word1], idx2 = d[word2]; + int i = 0, j = 0, m = idx1.size(), n = idx2.size(); + int ans = 1e5; + while (i < m && j < n) + { + int t = abs(idx1[i] - idx2[j]); + ans = min(ans, t); + if (idx1[i] < idx2[j]) ++i; + else ++j; } return ans; } @@ -109,14 +170,14 @@ public: ```go func findClosest(words []string, word1 string, word2 string) int { - idx1, idx2, ans := 100000, -100000, 100000 - for i, word := range words { + i, j, ans := 100000, -100000, 100000 + for k, word := range words { if word == word1 { - idx1 = i + i = k } else if word == word2 { - idx2 = i + j = k } - ans = min(ans, abs(idx1-idx2)) + ans = min(ans, abs(i-j)) } return ans } @@ -136,6 +197,37 @@ func abs(x int) int { } ``` +```go +func findClosest(words []string, word1 string, word2 string) int { + d := map[string][]int{} + for i, w := range words { + d[w] = append(d[w], i) + } + idx1, idx2 := d[word1], d[word2] + i, j, m, n := 0, 0, len(idx1), len(idx2) + ans := 100000 + for i < m && j < n { + t := abs(idx1[i] - idx2[j]) + if t < ans { + ans = t + } + if idx1[i] < idx2[j] { + i++ + } else { + j++ + } + } + return ans +} + +func abs(x int) int { + if x < 0 { + return -x + } + return x +} +``` + ### **Rust** ```rust diff --git a/lcci/17.11.Find Closest/README_EN.md b/lcci/17.11.Find Closest/README_EN.md index c123841abb6c7..ee34ffb7c7799 100644 --- a/lcci/17.11.Find Closest/README_EN.md +++ b/lcci/17.11.Find Closest/README_EN.md @@ -29,13 +29,31 @@ ```python class Solution: def findClosest(self, words: List[str], word1: str, word2: str) -> int: - idx1, idx2, ans = 10**5, -10**5, 10**5 - for i, word in enumerate(words): + i, j, ans = 1e5, -1e5, 1e5 + for k, word in enumerate(words): if word == word1: - idx1 = i + i = k elif word == word2: - idx2 = i - ans = min(ans, abs(idx1 - idx2)) + j = k + ans = min(ans, abs(i - j)) + return ans +``` + +```python +class Solution: + def findClosest(self, words: List[str], word1: str, word2: str) -> int: + d = defaultdict(list) + for i, w in enumerate(words): + d[w].append(i) + ans = 1e5 + idx1, idx2 = d[word1], d[word2] + i, j, m, n = 0, 0, len(idx1), len(idx2) + while i < m and j < n: + ans = min(ans, abs(idx1[i] - idx2[j])) + if idx1[i] < idx2[j]: + i += 1 + else: + j += 1 return ans ``` @@ -44,17 +62,39 @@ class Solution: ```java class Solution { public int findClosest(String[] words, String word1, String word2) { - int idx1 = 100000; - int idx2 = -100000; - int ans = 100000; - for (int i = 0; i < words.length; ++i) { - String word = words[i]; + int i = 100000, j = -100000, ans = 100000; + for (int k = 0; k < words.length; ++k) { + String word = words[k]; if (word.equals(word1)) { - idx1 = i; + i = k; } else if (word.equals(word2)) { - idx2 = i; + j = k; + } + ans = Math.min(ans, Math.abs(i - j)); + } + return ans; + } +} +``` + +```java +class Solution { + public int findClosest(String[] words, String word1, String word2) { + Map> d = new HashMap<>(); + for (int i = 0; i < words.length; ++i) { + d.computeIfAbsent(words[i], k -> new ArrayList<>()).add(i); + } + List idx1 = d.get(word1), idx2 = d.get(word2); + int i = 0, j = 0, m = idx1.size(), n = idx2.size(); + int ans = 100000; + while (i < m && j < n) { + int t = Math.abs(idx1.get(i) - idx2.get(j)); + ans = Math.min(ans, t); + if (idx1.get(i) < idx2.get(j)) { + ++i; + } else { + ++j; } - ans = Math.min(ans, Math.abs(idx1 - idx2)); } return ans; } @@ -88,13 +128,34 @@ function findClosest(words: string[], word1: string, word2: string): number { class Solution { public: int findClosest(vector& words, string word1, string word2) { - int idx1 = 1e5, idx2 = -1e5, ans = 1e5; - for (int i = 0; i < words.size(); ++i) + int i = 1e5, j = -1e5, ans = 1e5; + for (int k = 0; k < words.size(); ++k) { - string word = words[i]; - if (word == word1) idx1 = i; - else if (word == word2) idx2 = i; - ans = min(ans, abs(idx1 - idx2)); + string word = words[k]; + if (word == word1) i = k; + else if (word == word2) j = k; + ans = min(ans, abs(i - j)); + } + return ans; + } +}; +``` + +```cpp +class Solution { +public: + int findClosest(vector& words, string word1, string word2) { + unordered_map> d; + for (int i = 0; i < words.size(); ++i) d[words[i]].push_back(i); + vector idx1 = d[word1], idx2 = d[word2]; + int i = 0, j = 0, m = idx1.size(), n = idx2.size(); + int ans = 1e5; + while (i < m && j < n) + { + int t = abs(idx1[i] - idx2[j]); + ans = min(ans, t); + if (idx1[i] < idx2[j]) ++i; + else ++j; } return ans; } @@ -105,14 +166,14 @@ public: ```go func findClosest(words []string, word1 string, word2 string) int { - idx1, idx2, ans := 100000, -100000, 100000 - for i, word := range words { + i, j, ans := 100000, -100000, 100000 + for k, word := range words { if word == word1 { - idx1 = i + i = k } else if word == word2 { - idx2 = i + j = k } - ans = min(ans, abs(idx1-idx2)) + ans = min(ans, abs(i-j)) } return ans } @@ -132,6 +193,37 @@ func abs(x int) int { } ``` +```go +func findClosest(words []string, word1 string, word2 string) int { + d := map[string][]int{} + for i, w := range words { + d[w] = append(d[w], i) + } + idx1, idx2 := d[word1], d[word2] + i, j, m, n := 0, 0, len(idx1), len(idx2) + ans := 100000 + for i < m && j < n { + t := abs(idx1[i] - idx2[j]) + if t < ans { + ans = t + } + if idx1[i] < idx2[j] { + i++ + } else { + j++ + } + } + return ans +} + +func abs(x int) int { + if x < 0 { + return -x + } + return x +} +``` + ### **Rust** ```rust diff --git a/lcci/17.11.Find Closest/Solution.cpp b/lcci/17.11.Find Closest/Solution.cpp index 204836d31ea98..d3b00f657fb92 100644 --- a/lcci/17.11.Find Closest/Solution.cpp +++ b/lcci/17.11.Find Closest/Solution.cpp @@ -1,13 +1,13 @@ class Solution { public: int findClosest(vector& words, string word1, string word2) { - int idx1 = 1e5, idx2 = -1e5, ans = 1e5; - for (int i = 0; i < words.size(); ++i) + int i = 1e5, j = -1e5, ans = 1e5; + for (int k = 0; k < words.size(); ++k) { - string word = words[i]; - if (word == word1) idx1 = i; - else if (word == word2) idx2 = i; - ans = min(ans, abs(idx1 - idx2)); + string word = words[k]; + if (word == word1) i = k; + else if (word == word2) j = k; + ans = min(ans, abs(i - j)); } return ans; } diff --git a/lcci/17.11.Find Closest/Solution.go b/lcci/17.11.Find Closest/Solution.go index 4246759487433..2ed6c801dc01d 100644 --- a/lcci/17.11.Find Closest/Solution.go +++ b/lcci/17.11.Find Closest/Solution.go @@ -1,12 +1,12 @@ func findClosest(words []string, word1 string, word2 string) int { - idx1, idx2, ans := 100000, -100000, 100000 - for i, word := range words { + i, j, ans := 100000, -100000, 100000 + for k, word := range words { if word == word1 { - idx1 = i + i = k } else if word == word2 { - idx2 = i + j = k } - ans = min(ans, abs(idx1-idx2)) + ans = min(ans, abs(i-j)) } return ans } diff --git a/lcci/17.11.Find Closest/Solution.java b/lcci/17.11.Find Closest/Solution.java index 1a9210161d87d..84df1d4dcf926 100644 --- a/lcci/17.11.Find Closest/Solution.java +++ b/lcci/17.11.Find Closest/Solution.java @@ -1,16 +1,14 @@ class Solution { public int findClosest(String[] words, String word1, String word2) { - int idx1 = 100000; - int idx2 = -100000; - int ans = 100000; - for (int i = 0; i < words.length; ++i) { - String word = words[i]; + int i = 100000, j = -100000, ans = 100000; + for (int k = 0; k < words.length; ++k) { + String word = words[k]; if (word.equals(word1)) { - idx1 = i; + i = k; } else if (word.equals(word2)) { - idx2 = i; + j = k; } - ans = Math.min(ans, Math.abs(idx1 - idx2)); + ans = Math.min(ans, Math.abs(i - j)); } return ans; } diff --git a/lcci/17.11.Find Closest/Solution.py b/lcci/17.11.Find Closest/Solution.py index e7b382507946d..dc372a1ab3ad6 100644 --- a/lcci/17.11.Find Closest/Solution.py +++ b/lcci/17.11.Find Closest/Solution.py @@ -1,10 +1,10 @@ class Solution: def findClosest(self, words: List[str], word1: str, word2: str) -> int: - idx1, idx2, ans = 10**5, -(10**5), 10**5 - for i, word in enumerate(words): + i, j, ans = 1e5, -1e5, 1e5 + for k, word in enumerate(words): if word == word1: - idx1 = i + i = k elif word == word2: - idx2 = i - ans = min(ans, abs(idx1 - idx2)) + j = k + ans = min(ans, abs(i - j)) return ans diff --git a/solution/0200-0299/0201.Bitwise AND of Numbers Range/Solution.py b/solution/0200-0299/0201.Bitwise AND of Numbers Range/Solution.py index 1c059c28a580f..9dff701bdbfb8 100644 --- a/solution/0200-0299/0201.Bitwise AND of Numbers Range/Solution.py +++ b/solution/0200-0299/0201.Bitwise AND of Numbers Range/Solution.py @@ -1,5 +1,5 @@ class Solution: def rangeBitwiseAnd(self, left: int, right: int) -> int: while left < right: - right &= (right - 1) + right &= right - 1 return right diff --git a/solution/0400-0499/0401.Binary Watch/README.md b/solution/0400-0499/0401.Binary Watch/README.md index f4763cbf6c9be..54e70c5be343b 100644 --- a/solution/0400-0499/0401.Binary Watch/README.md +++ b/solution/0400-0499/0401.Binary Watch/README.md @@ -58,9 +58,15 @@ +**方法一:枚举组合** + 题目可转换为求 i(`i∈[0,12)`) 和 j(`j∈[0,60)`) 所有可能的组合。 -合法组合需要满足的条件是:i 的二进制形式中 1 的个数加上 j 的二进制形式中 1 的个数,结果等于 num。 +合法组合需要满足的条件是:i 的二进制形式中 1 的个数加上 j 的二进制形式中 1 的个数,结果等于 turnedOn。 + +**方法二:二进制枚举** + +利用 10 个二进制位表示手表,其中前 4 位代表小时,后 6 位代表分钟。枚举 `[0, 1 << 10)` 的所有数,找出合法的数。 @@ -70,8 +76,19 @@ ```python class Solution: - def readBinaryWatch(self, num: int) -> List[str]: - return ['{:d}:{:02d}'.format(i, j) for i in range(12) for j in range(60) if (bin(i) + bin(j)).count('1') == num] + def readBinaryWatch(self, turnedOn: int) -> List[str]: + return ['{:d}:{:02d}'.format(i, j) for i in range(12) for j in range(60) if (bin(i) + bin(j)).count('1') == turnedOn] +``` + +```python +class Solution: + def readBinaryWatch(self, turnedOn: int) -> List[str]: + ans = [] + for i in range(1 << 10): + h, m = i >> 6, i & 0b111111 + if h < 12 and m < 60 and i.bit_count() == turnedOn: + ans.append('{:d}:{:02d}'.format(h, m)) + return ans ``` ### **Java** @@ -80,20 +97,104 @@ class Solution: ```java class Solution { - public List readBinaryWatch(int num) { - List res = new ArrayList<>(); + public List readBinaryWatch(int turnedOn) { + List ans = new ArrayList<>(); for (int i = 0; i < 12; ++i) { for (int j = 0; j < 60; ++j) { - if (Integer.bitCount(i) + Integer.bitCount(j) == num) { - res.add(String.format("%d:%02d", i, j)); + if (Integer.bitCount(i) + Integer.bitCount(j) == turnedOn) { + ans.add(String.format("%d:%02d", i, j)); } } } - return res; + return ans; + } +} +``` + +```java +class Solution { + public List readBinaryWatch(int turnedOn) { + List ans = new ArrayList<>(); + for (int i = 0; i < 1 << 10; ++i) { + int h = i >> 6, m = i & 0b111111; + if (h < 12 && m < 60 && Integer.bitCount(i) == turnedOn) { + ans.add(String.format("%d:%02d", h, m)); + } + } + return ans; } } ``` +### **C++** + +```cpp +class Solution { +public: + vector readBinaryWatch(int turnedOn) { + vector ans; + for (int i = 0; i < 12; ++i) + { + for (int j = 0; j < 60; ++j) + { + if (__builtin_popcount(i) + __builtin_popcount(j) == turnedOn) + { + ans.push_back(to_string(i) + ":" + (j < 10 ? "0" : "") + to_string(j)); + } + } + } + return ans; + } +}; +``` + +```cpp +class Solution { +public: + vector readBinaryWatch(int turnedOn) { + vector ans; + for (int i = 0; i < 1 << 10; ++i) + { + int h = i >> 6, m = i & 0b111111; + if (h < 12 && m < 60 && __builtin_popcount(i) == turnedOn) + { + ans.push_back(to_string(h) + ":" + (m < 10 ? "0" : "") + to_string(m)); + } + } + return ans; + } +}; +``` + +### **Go** + +```go +func readBinaryWatch(turnedOn int) []string { + var ans []string + for i := 0; i < 12; i++ { + for j := 0; j < 60; j++ { + if bits.OnesCount(uint(i))+bits.OnesCount(uint(j)) == turnedOn { + ans = append(ans, fmt.Sprintf("%d:%02d", i, j)) + } + } + } + return ans +} +``` + +```go +func readBinaryWatch(turnedOn int) []string { + var ans []string + for i := 0; i < 1<<10; i++ { + h, m := i>>6, i&0b111111 + if h < 12 && m < 60 && bits.OnesCount(uint(i)) == turnedOn { + ans = append(ans, fmt.Sprintf("%d:%02d", h, m)) + } + } + return ans +} +``` + ### **TypeScript** ```ts diff --git a/solution/0400-0499/0401.Binary Watch/README_EN.md b/solution/0400-0499/0401.Binary Watch/README_EN.md index 1960358466757..c14db63cd9e90 100644 --- a/solution/0400-0499/0401.Binary Watch/README_EN.md +++ b/solution/0400-0499/0401.Binary Watch/README_EN.md @@ -49,28 +49,123 @@ ```python class Solution: - def readBinaryWatch(self, num: int) -> List[str]: - return ['{:d}:{:02d}'.format(i, j) for i in range(12) for j in range(60) if (bin(i) + bin(j)).count('1') == num] + def readBinaryWatch(self, turnedOn: int) -> List[str]: + return ['{:d}:{:02d}'.format(i, j) for i in range(12) for j in range(60) if (bin(i) + bin(j)).count('1') == turnedOn] +``` + +```python +class Solution: + def readBinaryWatch(self, turnedOn: int) -> List[str]: + ans = [] + for i in range(1 << 10): + h, m = i >> 6, i & 0b111111 + if h < 12 and m < 60 and i.bit_count() == turnedOn: + ans.append('{:d}:{:02d}'.format(h, m)) + return ans ``` ### **Java** ```java class Solution { - public List readBinaryWatch(int num) { - List res = new ArrayList<>(); + public List readBinaryWatch(int turnedOn) { + List ans = new ArrayList<>(); for (int i = 0; i < 12; ++i) { for (int j = 0; j < 60; ++j) { - if (Integer.bitCount(i) + Integer.bitCount(j) == num) { - res.add(String.format("%d:%02d", i, j)); + if (Integer.bitCount(i) + Integer.bitCount(j) == turnedOn) { + ans.add(String.format("%d:%02d", i, j)); } } } - return res; + return ans; } } ``` +```java +class Solution { + public List readBinaryWatch(int turnedOn) { + List ans = new ArrayList<>(); + for (int i = 0; i < 1 << 10; ++i) { + int h = i >> 6, m = i & 0b111111; + if (h < 12 && m < 60 && Integer.bitCount(i) == turnedOn) { + ans.add(String.format("%d:%02d", h, m)); + } + } + return ans; + } +} +``` + +### **C++** + +```cpp +class Solution { +public: + vector readBinaryWatch(int turnedOn) { + vector ans; + for (int i = 0; i < 12; ++i) + { + for (int j = 0; j < 60; ++j) + { + if (__builtin_popcount(i) + __builtin_popcount(j) == turnedOn) + { + ans.push_back(to_string(i) + ":" + (j < 10 ? "0" : "") + to_string(j)); + } + } + } + return ans; + } +}; +``` + +```cpp +class Solution { +public: + vector readBinaryWatch(int turnedOn) { + vector ans; + for (int i = 0; i < 1 << 10; ++i) + { + int h = i >> 6, m = i & 0b111111; + if (h < 12 && m < 60 && __builtin_popcount(i) == turnedOn) + { + ans.push_back(to_string(h) + ":" + (m < 10 ? "0" : "") + to_string(m)); + } + } + return ans; + } +}; +``` + +### **Go** + +```go +func readBinaryWatch(turnedOn int) []string { + var ans []string + for i := 0; i < 12; i++ { + for j := 0; j < 60; j++ { + if bits.OnesCount(uint(i))+bits.OnesCount(uint(j)) == turnedOn { + ans = append(ans, fmt.Sprintf("%d:%02d", i, j)) + } + } + } + return ans +} +``` + +```go +func readBinaryWatch(turnedOn int) []string { + var ans []string + for i := 0; i < 1<<10; i++ { + h, m := i>>6, i&0b111111 + if h < 12 && m < 60 && bits.OnesCount(uint(i)) == turnedOn { + ans = append(ans, fmt.Sprintf("%d:%02d", h, m)) + } + } + return ans +} +``` + ### **TypeScript** ```ts diff --git a/solution/0400-0499/0401.Binary Watch/Solution.cpp b/solution/0400-0499/0401.Binary Watch/Solution.cpp new file mode 100644 index 0000000000000..32595791865b6 --- /dev/null +++ b/solution/0400-0499/0401.Binary Watch/Solution.cpp @@ -0,0 +1,17 @@ +class Solution { +public: + vector readBinaryWatch(int turnedOn) { + vector ans; + for (int i = 0; i < 12; ++i) + { + for (int j = 0; j < 60; ++j) + { + if (__builtin_popcount(i) + __builtin_popcount(j) == turnedOn) + { + ans.push_back(to_string(i) + ":" + (j < 10 ? "0" : "") + to_string(j)); + } + } + } + return ans; + } +}; \ No newline at end of file diff --git a/solution/0400-0499/0401.Binary Watch/Solution.go b/solution/0400-0499/0401.Binary Watch/Solution.go new file mode 100644 index 0000000000000..a82c976cb3b91 --- /dev/null +++ b/solution/0400-0499/0401.Binary Watch/Solution.go @@ -0,0 +1,11 @@ +func readBinaryWatch(turnedOn int) []string { + var ans []string + for i := 0; i < 12; i++ { + for j := 0; j < 60; j++ { + if bits.OnesCount(uint(i))+bits.OnesCount(uint(j)) == turnedOn { + ans = append(ans, fmt.Sprintf("%d:%02d", i, j)) + } + } + } + return ans +} \ No newline at end of file diff --git a/solution/0400-0499/0401.Binary Watch/Solution.java b/solution/0400-0499/0401.Binary Watch/Solution.java index f6c57eb8d140b..732bbfcd9a02d 100644 --- a/solution/0400-0499/0401.Binary Watch/Solution.java +++ b/solution/0400-0499/0401.Binary Watch/Solution.java @@ -1,13 +1,13 @@ class Solution { - public List readBinaryWatch(int num) { - List res = new ArrayList<>(); + public List readBinaryWatch(int turnedOn) { + List ans = new ArrayList<>(); for (int i = 0; i < 12; ++i) { for (int j = 0; j < 60; ++j) { - if (Integer.bitCount(i) + Integer.bitCount(j) == num) { - res.add(String.format("%d:%02d", i, j)); + if (Integer.bitCount(i) + Integer.bitCount(j) == turnedOn) { + ans.add(String.format("%d:%02d", i, j)); } } } - return res; + return ans; } } \ No newline at end of file diff --git a/solution/0400-0499/0401.Binary Watch/Solution.py b/solution/0400-0499/0401.Binary Watch/Solution.py index 2c11f240aa30a..1311bc3bb3a0b 100644 --- a/solution/0400-0499/0401.Binary Watch/Solution.py +++ b/solution/0400-0499/0401.Binary Watch/Solution.py @@ -1,8 +1,8 @@ class Solution: - def readBinaryWatch(self, num: int) -> List[str]: + def readBinaryWatch(self, turnedOn: int) -> List[str]: return [ '{:d}:{:02d}'.format(i, j) for i in range(12) for j in range(60) - if (bin(i) + bin(j)).count('1') == num + if (bin(i) + bin(j)).count('1') == turnedOn ] diff --git a/solution/1300-1399/1383.Maximum Performance of a Team/Solution.py b/solution/1300-1399/1383.Maximum Performance of a Team/Solution.py index 8facec1437da6..92aa29c0e8e14 100644 --- a/solution/1300-1399/1383.Maximum Performance of a Team/Solution.py +++ b/solution/1300-1399/1383.Maximum Performance of a Team/Solution.py @@ -1,5 +1,7 @@ class Solution: - def maxPerformance(self, n: int, speed: List[int], efficiency: List[int], k: int) -> int: + def maxPerformance( + self, n: int, speed: List[int], efficiency: List[int], k: int + ) -> int: team = [(s, e) for s, e in zip(speed, efficiency)] team.sort(key=lambda x: -x[1]) q = []