diff --git a/solution/1000-1099/1078.Occurrences After Bigram/README.md b/solution/1000-1099/1078.Occurrences After Bigram/README.md index efad9acc6f..e2105bd12c 100644 --- a/solution/1000-1099/1078.Occurrences After Bigram/README.md +++ b/solution/1000-1099/1078.Occurrences After Bigram/README.md @@ -55,11 +55,10 @@ ```python class Solution: def findOcurrences(self, text: str, first: str, second: str) -> List[str]: - words = text.split(' ') + ws = text.split() + n = len(ws) return [ - words[i + 2] - for i in range(len(words) - 2) - if words[i] == first and words[i + 1] == second + ws[i + 2] for i in range(n - 2) if ws[i] == first and ws[i + 1] == second ] ``` diff --git a/solution/1000-1099/1078.Occurrences After Bigram/README_EN.md b/solution/1000-1099/1078.Occurrences After Bigram/README_EN.md index a79f1cde2a..283f3ceeba 100644 --- a/solution/1000-1099/1078.Occurrences After Bigram/README_EN.md +++ b/solution/1000-1099/1078.Occurrences After Bigram/README_EN.md @@ -36,11 +36,10 @@ ```python class Solution: def findOcurrences(self, text: str, first: str, second: str) -> List[str]: - words = text.split(' ') + ws = text.split() + n = len(ws) return [ - words[i + 2] - for i in range(len(words) - 2) - if words[i] == first and words[i + 1] == second + ws[i + 2] for i in range(n - 2) if ws[i] == first and ws[i + 1] == second ] ``` diff --git a/solution/1000-1099/1078.Occurrences After Bigram/Solution.py b/solution/1000-1099/1078.Occurrences After Bigram/Solution.py index 7767dfc769..5589ed7995 100644 --- a/solution/1000-1099/1078.Occurrences After Bigram/Solution.py +++ b/solution/1000-1099/1078.Occurrences After Bigram/Solution.py @@ -1,8 +1,7 @@ class Solution: def findOcurrences(self, text: str, first: str, second: str) -> List[str]: - words = text.split(' ') + ws = text.split() + n = len(ws) return [ - words[i + 2] - for i in range(len(words) - 2) - if words[i] == first and words[i + 1] == second + ws[i + 2] for i in range(n - 2) if ws[i] == first and ws[i + 1] == second ] diff --git a/solution/1000-1099/1085.Sum of Digits in the Minimum Number/README.md b/solution/1000-1099/1085.Sum of Digits in the Minimum Number/README.md index 631ad9ce77..50b03cfae5 100644 --- a/solution/1000-1099/1085.Sum of Digits in the Minimum Number/README.md +++ b/solution/1000-1099/1085.Sum of Digits in the Minimum Number/README.md @@ -45,6 +45,12 @@ +**方法一:模拟** + +我们先找到数组中的最小值,记为 $x$。然后计算 $x$ 的各个数位上的数字之和,记为 $s$。最后判断 $s$ 是否为奇数,若是则返回 $0$,否则返回 $1$。 + +时间复杂度 $O(n)$,空间复杂度 $O(1)$。其中 $n$ 为数组的长度。 + ### **Python3** @@ -59,7 +65,7 @@ class Solution: while x: s += x % 10 x //= 10 - return 0 if s % 2 else 1 + return s & 1 ^ 1 ``` ### **Java** @@ -69,16 +75,15 @@ class Solution: ```java class Solution { public int sumOfDigits(int[] nums) { - int x = nums[0]; + int x = 100; for (int v : nums) { x = Math.min(x, v); } int s = 0; - while (x != 0) { + for (; x > 0; x /= 10) { s += x % 10; - x /= 10; } - return 1 - s % 2; + return s & 1 ^ 1; } } ``` @@ -89,11 +94,12 @@ class Solution { class Solution { public: int sumOfDigits(vector& nums) { - int x = nums[0]; - for (int& v : nums) x = min(x, v); + int x = *min_element(nums.begin(), nums.end()); int s = 0; - for (; x != 0; x /= 10) s += x % 10; - return 1 - s % 2; + for (; x > 0; x /= 10) { + s += x % 10; + } + return s & 1 ^ 1; } }; ``` @@ -102,17 +108,17 @@ public: ```go func sumOfDigits(nums []int) int { - x := nums[0] + x := 100 for _, v := range nums { if v < x { x = v } } s := 0 - for ; x != 0; x /= 10 { + for ; x > 0; x /= 10 { s += x % 10 } - return 1 - s%2 + return s&1 ^ 1 } ``` diff --git a/solution/1000-1099/1085.Sum of Digits in the Minimum Number/README_EN.md b/solution/1000-1099/1085.Sum of Digits in the Minimum Number/README_EN.md index 242458c7ee..cc11e105ed 100644 --- a/solution/1000-1099/1085.Sum of Digits in the Minimum Number/README_EN.md +++ b/solution/1000-1099/1085.Sum of Digits in the Minimum Number/README_EN.md @@ -45,7 +45,7 @@ class Solution: while x: s += x % 10 x //= 10 - return 0 if s % 2 else 1 + return s & 1 ^ 1 ``` ### **Java** @@ -53,16 +53,15 @@ class Solution: ```java class Solution { public int sumOfDigits(int[] nums) { - int x = nums[0]; + int x = 100; for (int v : nums) { x = Math.min(x, v); } int s = 0; - while (x != 0) { + for (; x > 0; x /= 10) { s += x % 10; - x /= 10; } - return 1 - s % 2; + return s & 1 ^ 1; } } ``` @@ -73,11 +72,12 @@ class Solution { class Solution { public: int sumOfDigits(vector& nums) { - int x = nums[0]; - for (int& v : nums) x = min(x, v); + int x = *min_element(nums.begin(), nums.end()); int s = 0; - for (; x != 0; x /= 10) s += x % 10; - return 1 - s % 2; + for (; x > 0; x /= 10) { + s += x % 10; + } + return s & 1 ^ 1; } }; ``` @@ -86,17 +86,17 @@ public: ```go func sumOfDigits(nums []int) int { - x := nums[0] + x := 100 for _, v := range nums { if v < x { x = v } } s := 0 - for ; x != 0; x /= 10 { + for ; x > 0; x /= 10 { s += x % 10 } - return 1 - s%2 + return s&1 ^ 1 } ``` diff --git a/solution/1000-1099/1085.Sum of Digits in the Minimum Number/Solution.cpp b/solution/1000-1099/1085.Sum of Digits in the Minimum Number/Solution.cpp index 4b4aa1244e..90e5cc6f0b 100644 --- a/solution/1000-1099/1085.Sum of Digits in the Minimum Number/Solution.cpp +++ b/solution/1000-1099/1085.Sum of Digits in the Minimum Number/Solution.cpp @@ -1,10 +1,11 @@ class Solution { public: int sumOfDigits(vector& nums) { - int x = nums[0]; - for (int& v : nums) x = min(x, v); + int x = *min_element(nums.begin(), nums.end()); int s = 0; - for (; x != 0; x /= 10) s += x % 10; - return 1 - s % 2; + for (; x > 0; x /= 10) { + s += x % 10; + } + return s & 1 ^ 1; } }; \ No newline at end of file diff --git a/solution/1000-1099/1085.Sum of Digits in the Minimum Number/Solution.go b/solution/1000-1099/1085.Sum of Digits in the Minimum Number/Solution.go index b3d3ffb624..5f98d49e2a 100644 --- a/solution/1000-1099/1085.Sum of Digits in the Minimum Number/Solution.go +++ b/solution/1000-1099/1085.Sum of Digits in the Minimum Number/Solution.go @@ -1,13 +1,13 @@ func sumOfDigits(nums []int) int { - x := nums[0] + x := 100 for _, v := range nums { if v < x { x = v } } s := 0 - for ; x != 0; x /= 10 { + for ; x > 0; x /= 10 { s += x % 10 } - return 1 - s%2 + return s&1 ^ 1 } \ No newline at end of file diff --git a/solution/1000-1099/1085.Sum of Digits in the Minimum Number/Solution.java b/solution/1000-1099/1085.Sum of Digits in the Minimum Number/Solution.java index 650d628227..b3a57955ac 100644 --- a/solution/1000-1099/1085.Sum of Digits in the Minimum Number/Solution.java +++ b/solution/1000-1099/1085.Sum of Digits in the Minimum Number/Solution.java @@ -1,14 +1,13 @@ class Solution { public int sumOfDigits(int[] nums) { - int x = nums[0]; + int x = 100; for (int v : nums) { x = Math.min(x, v); } int s = 0; - while (x != 0) { + for (; x > 0; x /= 10) { s += x % 10; - x /= 10; } - return 1 - s % 2; + return s & 1 ^ 1; } } \ No newline at end of file diff --git a/solution/1000-1099/1085.Sum of Digits in the Minimum Number/Solution.py b/solution/1000-1099/1085.Sum of Digits in the Minimum Number/Solution.py index b8398bb3ee..58f614cd76 100644 --- a/solution/1000-1099/1085.Sum of Digits in the Minimum Number/Solution.py +++ b/solution/1000-1099/1085.Sum of Digits in the Minimum Number/Solution.py @@ -5,4 +5,4 @@ class Solution: while x: s += x % 10 x //= 10 - return 0 if s % 2 else 1 + return s & 1 ^ 1 diff --git a/solution/main.py b/solution/main.py index 7e760f9d22..73b1ec3cd7 100644 --- a/solution/main.py +++ b/solution/main.py @@ -134,10 +134,13 @@ def generate_summary(result): def refresh(result): """update problems""" pattern = re.compile("src=\"(.*?)\"") + skip_question_ids = {1599} for question in result: front_question_id = question['frontend_question_id'] print(front_question_id) + if int(front_question_id) in skip_question_ids: + continue title = question['title_cn'] title_en = question['title_en']