From 5d7fdaf2327f3a672e48173551ee56888e1dc11d Mon Sep 17 00:00:00 2001 From: rain84 Date: Mon, 1 Jul 2024 16:49:15 +0300 Subject: [PATCH 01/13] feat: add ts solution to lc problem: No.1550 --- .../1550.Three Consecutive Odds/README.md | 16 ++++++++++++++++ .../1550.Three Consecutive Odds/README_EN.md | 16 ++++++++++++++++ .../1550.Three Consecutive Odds/Solution2.ts | 11 +++++++++++ 3 files changed, 43 insertions(+) create mode 100644 solution/1500-1599/1550.Three Consecutive Odds/Solution2.ts diff --git a/solution/1500-1599/1550.Three Consecutive Odds/README.md b/solution/1500-1599/1550.Three Consecutive Odds/README.md index 7a86894d76374..e9619608b48a2 100644 --- a/solution/1500-1599/1550.Three Consecutive Odds/README.md +++ b/solution/1500-1599/1550.Three Consecutive Odds/README.md @@ -174,6 +174,22 @@ class Solution: return False ``` +#### TypeScript + +```ts +function threeConsecutiveOdds(arr: number[]): boolean { + const n = arr.length; + if (n < 3) return false; + + for (let i = 2; i < n; i++) { + if (arr[i - 2] & arr[i - 1] & arr[i] & 1) { + return true; + } + } + return false; +} +``` + diff --git a/solution/1500-1599/1550.Three Consecutive Odds/README_EN.md b/solution/1500-1599/1550.Three Consecutive Odds/README_EN.md index 407fbacf7bf52..2d2612357760e 100644 --- a/solution/1500-1599/1550.Three Consecutive Odds/README_EN.md +++ b/solution/1500-1599/1550.Three Consecutive Odds/README_EN.md @@ -170,6 +170,22 @@ class Solution: return False ``` +#### TypeScript + +```ts +function threeConsecutiveOdds(arr: number[]): boolean { + const n = arr.length; + if (n < 3) return false; + + for (let i = 2; i < n; i++) { + if (arr[i - 2] & arr[i - 1] & arr[i] & 1) { + return true; + } + } + return false; +} +``` + diff --git a/solution/1500-1599/1550.Three Consecutive Odds/Solution2.ts b/solution/1500-1599/1550.Three Consecutive Odds/Solution2.ts new file mode 100644 index 0000000000000..d55454d58ed92 --- /dev/null +++ b/solution/1500-1599/1550.Three Consecutive Odds/Solution2.ts @@ -0,0 +1,11 @@ +function threeConsecutiveOdds(arr: number[]): boolean { + const n = arr.length; + if (n < 3) return false; + + for (let i = 2; i < n; i++) { + if (arr[i - 2] & arr[i - 1] & arr[i] & 1) { + return true; + } + } + return false; +} From 0fdfd6d2b1a859b98ab86b3a9c0a375707bae75a Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Tue, 2 Jul 2024 08:43:52 +0800 Subject: [PATCH 02/13] Update README.md --- .../1550.Three Consecutive Odds/README.md | 123 ++++++++++++------ 1 file changed, 86 insertions(+), 37 deletions(-) diff --git a/solution/1500-1599/1550.Three Consecutive Odds/README.md b/solution/1500-1599/1550.Three Consecutive Odds/README.md index e9619608b48a2..36d12e53d91a7 100644 --- a/solution/1500-1599/1550.Three Consecutive Odds/README.md +++ b/solution/1500-1599/1550.Three Consecutive Odds/README.md @@ -51,11 +51,15 @@ tags: -### 方法一:遍历数组 +### 方法一:遍历 + 计数 -直接遍历数组,统计连续奇数的个数,如果个数达到 3,则返回 `true`,否则遍历结束,返回 `false`。 +我们用一个变量 $\text{cnt}$ 记录当前连续奇数的个数。 -时间复杂度 $O(n)$,空间复杂度 $O(1)$,其中 $n$ 为数组 `arr` 的长度。 +接下来,我们遍历数组,如果当前元素是奇数,则 $\text{cnt}$ 加一,如果 $\text{cnt}$ 等于 3,则返回 $\text{True}$。如果当前元素是偶数,则 $\text{cnt}$ 置零。 + +遍历结束后,如果没有找到连续三个奇数,则返回 $\text{False}$。 + +时间复杂度 $O(n)$,其中 $n$ 是数组 $\text{arr}$ 的长度。空间复杂度 $O(1)$。 @@ -65,13 +69,13 @@ tags: class Solution: def threeConsecutiveOdds(self, arr: List[int]) -> bool: cnt = 0 - for v in arr: - if v & 1: + for x in arr: + if x & 1: cnt += 1 + if cnt == 3: + return True else: cnt = 0 - if cnt == 3: - return True return False ``` @@ -81,15 +85,14 @@ class Solution: class Solution { public boolean threeConsecutiveOdds(int[] arr) { int cnt = 0; - for (int v : arr) { - if (v % 2 == 1) { - ++cnt; + for (int x : arr) { + if (x % 2 == 1) { + if (++cnt == 3) { + return true; + } } else { cnt = 0; } - if (cnt == 3) { - return true; - } } return false; } @@ -103,12 +106,14 @@ class Solution { public: bool threeConsecutiveOdds(vector& arr) { int cnt = 0; - for (int v : arr) { - if (v & 1) - ++cnt; - else + for (int x : arr) { + if (x & 1) { + if (++cnt == 3) { + return true; + } + } else { cnt = 0; - if (cnt == 3) return true; + } } return false; } @@ -120,15 +125,15 @@ public: ```go func threeConsecutiveOdds(arr []int) bool { cnt := 0 - for _, v := range arr { - if v%2 == 1 { + for _, x := range arr { + if x&1 == 1 { cnt++ + if cnt == 3 { + return true + } } else { cnt = 0 } - if cnt == 3 { - return true - } } return false } @@ -139,15 +144,14 @@ func threeConsecutiveOdds(arr []int) bool { ```ts function threeConsecutiveOdds(arr: number[]): boolean { let cnt = 0; - for (const v of arr) { - if (v & 1) { - ++cnt; + for (const x of arr) { + if (x & 1) { + if (++cnt == 3) { + return true; + } } else { cnt = 0; } - if (cnt == 3) { - return true; - } } return false; } @@ -159,7 +163,13 @@ function threeConsecutiveOdds(arr: number[]): boolean { -### 方法二 +### 方法二:遍历 + 位运算 + +根据位运算的性质,两个数进行按位与运算是奇数,当且仅当两个数都是奇数。如果有连续三个数按位与运算的结果是奇数,那么这三个数都是奇数。 + +因此,我们只需要遍历数组,判断是否存在连续三个数的按位与结果是否是奇数即可,如果存在则返回 $\text{True}$,否则返回 $\text{False}$。 + +时间复杂度 $O(n)$,其中 $n$ 是数组 $\text{arr}$ 的长度。空间复杂度 $O(1)$。 @@ -168,10 +178,51 @@ function threeConsecutiveOdds(arr: number[]): boolean { ```python class Solution: def threeConsecutiveOdds(self, arr: List[int]) -> bool: - for i in range(len(arr) - 2): - if arr[i] % 2 + arr[i + 1] % 2 + arr[i + 2] % 2 == 3: - return True - return False + return any(x & arr[i + 1] & arr[i + 2] & 1 for i, x in enumerate(arr[:-2])) +``` + +#### Java + +```java +class Solution { + public boolean threeConsecutiveOdds(int[] arr) { + for (int i = 2, n = arr.length; i < n; ++i) { + if ((arr[i - 2] & arr[i - 1] & arr[i] & 1) == 1) { + return true; + } + } + return false; + } +} +``` + +#### C++ + +```cpp +class Solution { +public: + bool threeConsecutiveOdds(vector& arr) { + for (int i = 2, n = arr.size(); i < n; ++i) { + if (arr[i - 2] & arr[i - 1] & arr[i] & 1) { + return true; + } + } + return false; + } +}; +``` + +#### Go + +```go +func threeConsecutiveOdds(arr []int) bool { + for i, n := 2, len(arr); i < n; i++ { + if arr[i-2]&arr[i-1]&arr[i]&1 == 1 { + return true + } + } + return false +} ``` #### TypeScript @@ -179,9 +230,7 @@ class Solution: ```ts function threeConsecutiveOdds(arr: number[]): boolean { const n = arr.length; - if (n < 3) return false; - - for (let i = 2; i < n; i++) { + for (let i = 2; i < n; ++i) { if (arr[i - 2] & arr[i - 1] & arr[i] & 1) { return true; } From cbb6a0e1277e461b92244d6d7f0c52498d6b3860 Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Tue, 2 Jul 2024 08:44:03 +0800 Subject: [PATCH 03/13] Update README_EN.md --- .../1550.Three Consecutive Odds/README_EN.md | 123 +++++++++++++----- 1 file changed, 88 insertions(+), 35 deletions(-) diff --git a/solution/1500-1599/1550.Three Consecutive Odds/README_EN.md b/solution/1500-1599/1550.Three Consecutive Odds/README_EN.md index 2d2612357760e..f6b6381f1ceea 100644 --- a/solution/1500-1599/1550.Three Consecutive Odds/README_EN.md +++ b/solution/1500-1599/1550.Three Consecutive Odds/README_EN.md @@ -51,7 +51,15 @@ Given an integer array arr, return true if there -### Solution 1 +### Solution 1: Iteration + Counting + +We use a variable $\text{cnt}$ to record the current count of consecutive odd numbers. + +Next, we iterate through the array. If the current element is odd, then $\text{cnt}$ is incremented by one. If $\text{cnt}$ equals 3, then return $\text{True}$. If the current element is even, then $\text{cnt}$ is reset to zero. + +After the iteration, if three consecutive odd numbers are not found, then return $\text{False}$. + +The time complexity is $O(n)$, where $n$ is the length of the array $\text{arr}$. The space complexity is $O(1)$. @@ -61,13 +69,13 @@ Given an integer array arr, return true if there class Solution: def threeConsecutiveOdds(self, arr: List[int]) -> bool: cnt = 0 - for v in arr: - if v & 1: + for x in arr: + if x & 1: cnt += 1 + if cnt == 3: + return True else: cnt = 0 - if cnt == 3: - return True return False ``` @@ -77,15 +85,14 @@ class Solution: class Solution { public boolean threeConsecutiveOdds(int[] arr) { int cnt = 0; - for (int v : arr) { - if (v % 2 == 1) { - ++cnt; + for (int x : arr) { + if (x % 2 == 1) { + if (++cnt == 3) { + return true; + } } else { cnt = 0; } - if (cnt == 3) { - return true; - } } return false; } @@ -99,12 +106,14 @@ class Solution { public: bool threeConsecutiveOdds(vector& arr) { int cnt = 0; - for (int v : arr) { - if (v & 1) - ++cnt; - else + for (int x : arr) { + if (x & 1) { + if (++cnt == 3) { + return true; + } + } else { cnt = 0; - if (cnt == 3) return true; + } } return false; } @@ -116,15 +125,15 @@ public: ```go func threeConsecutiveOdds(arr []int) bool { cnt := 0 - for _, v := range arr { - if v%2 == 1 { + for _, x := range arr { + if x&1 == 1 { cnt++ + if cnt == 3 { + return true + } } else { cnt = 0 } - if cnt == 3 { - return true - } } return false } @@ -135,15 +144,14 @@ func threeConsecutiveOdds(arr []int) bool { ```ts function threeConsecutiveOdds(arr: number[]): boolean { let cnt = 0; - for (const v of arr) { - if (v & 1) { - ++cnt; + for (const x of arr) { + if (x & 1) { + if (++cnt == 3) { + return true; + } } else { cnt = 0; } - if (cnt == 3) { - return true; - } } return false; } @@ -155,7 +163,13 @@ function threeConsecutiveOdds(arr: number[]): boolean { -### Solution 2 +### Solution 2: Iteration + Bitwise Operation + +Based on the properties of bitwise operations, the result of a bitwise AND operation between two numbers is odd if and only if both numbers are odd. If there are three consecutive numbers whose bitwise AND result is odd, then these three numbers are all odd. + +Therefore, we only need to iterate through the array and check if there exists three consecutive numbers whose bitwise AND result is odd. If such numbers exist, return $\text{True}$; otherwise, return $\text{False}$. + +The time complexity is $O(n)$, where $n$ is the length of the array $\text{arr}$. The space complexity is $O(1)$. @@ -164,10 +178,51 @@ function threeConsecutiveOdds(arr: number[]): boolean { ```python class Solution: def threeConsecutiveOdds(self, arr: List[int]) -> bool: - for i in range(len(arr) - 2): - if arr[i] % 2 + arr[i + 1] % 2 + arr[i + 2] % 2 == 3: - return True - return False + return any(x & arr[i + 1] & arr[i + 2] & 1 for i, x in enumerate(arr[:-2])) +``` + +#### Java + +```java +class Solution { + public boolean threeConsecutiveOdds(int[] arr) { + for (int i = 2, n = arr.length; i < n; ++i) { + if ((arr[i - 2] & arr[i - 1] & arr[i] & 1) == 1) { + return true; + } + } + return false; + } +} +``` + +#### C++ + +```cpp +class Solution { +public: + bool threeConsecutiveOdds(vector& arr) { + for (int i = 2, n = arr.size(); i < n; ++i) { + if (arr[i - 2] & arr[i - 1] & arr[i] & 1) { + return true; + } + } + return false; + } +}; +``` + +#### Go + +```go +func threeConsecutiveOdds(arr []int) bool { + for i, n := 2, len(arr); i < n; i++ { + if arr[i-2]&arr[i-1]&arr[i]&1 == 1 { + return true + } + } + return false +} ``` #### TypeScript @@ -175,9 +230,7 @@ class Solution: ```ts function threeConsecutiveOdds(arr: number[]): boolean { const n = arr.length; - if (n < 3) return false; - - for (let i = 2; i < n; i++) { + for (let i = 2; i < n; ++i) { if (arr[i - 2] & arr[i - 1] & arr[i] & 1) { return true; } From 00307a87fe73872d851c0a0ba6a045177b1e998d Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Tue, 2 Jul 2024 08:44:17 +0800 Subject: [PATCH 04/13] Update Solution2.ts --- solution/1500-1599/1550.Three Consecutive Odds/Solution2.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/solution/1500-1599/1550.Three Consecutive Odds/Solution2.ts b/solution/1500-1599/1550.Three Consecutive Odds/Solution2.ts index d55454d58ed92..eac001621e185 100644 --- a/solution/1500-1599/1550.Three Consecutive Odds/Solution2.ts +++ b/solution/1500-1599/1550.Three Consecutive Odds/Solution2.ts @@ -1,8 +1,6 @@ function threeConsecutiveOdds(arr: number[]): boolean { const n = arr.length; - if (n < 3) return false; - - for (let i = 2; i < n; i++) { + for (let i = 2; i < n; ++i) { if (arr[i - 2] & arr[i - 1] & arr[i] & 1) { return true; } From 9f233882160dc9a6d0e0d76d91b431578e547c44 Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Tue, 2 Jul 2024 08:44:54 +0800 Subject: [PATCH 05/13] Update Solution.py --- .../1500-1599/1550.Three Consecutive Odds/Solution.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/solution/1500-1599/1550.Three Consecutive Odds/Solution.py b/solution/1500-1599/1550.Three Consecutive Odds/Solution.py index ee2e71c3c26c7..017973cde2213 100644 --- a/solution/1500-1599/1550.Three Consecutive Odds/Solution.py +++ b/solution/1500-1599/1550.Three Consecutive Odds/Solution.py @@ -1,11 +1,11 @@ class Solution: def threeConsecutiveOdds(self, arr: List[int]) -> bool: cnt = 0 - for v in arr: - if v & 1: + for x in arr: + if x & 1: cnt += 1 + if cnt == 3: + return True else: cnt = 0 - if cnt == 3: - return True return False From 2ff611aa18e844e0583d9e5516ea7fa5660eb65c Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Tue, 2 Jul 2024 08:45:02 +0800 Subject: [PATCH 06/13] Update Solution.java --- .../1550.Three Consecutive Odds/Solution.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/solution/1500-1599/1550.Three Consecutive Odds/Solution.java b/solution/1500-1599/1550.Three Consecutive Odds/Solution.java index 82a56aef16f60..e578aab7468a8 100644 --- a/solution/1500-1599/1550.Three Consecutive Odds/Solution.java +++ b/solution/1500-1599/1550.Three Consecutive Odds/Solution.java @@ -1,16 +1,15 @@ class Solution { public boolean threeConsecutiveOdds(int[] arr) { int cnt = 0; - for (int v : arr) { - if (v % 2 == 1) { - ++cnt; + for (int x : arr) { + if (x % 2 == 1) { + if (++cnt == 3) { + return true; + } } else { cnt = 0; } - if (cnt == 3) { - return true; - } } return false; } -} \ No newline at end of file +} From 9dfb068dbbeef388c1121fbf0077517cc891d8d5 Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Tue, 2 Jul 2024 08:45:10 +0800 Subject: [PATCH 07/13] Update Solution.cpp --- .../1550.Three Consecutive Odds/Solution.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/solution/1500-1599/1550.Three Consecutive Odds/Solution.cpp b/solution/1500-1599/1550.Three Consecutive Odds/Solution.cpp index 93ea48ab51c14..e7d1c971422e4 100644 --- a/solution/1500-1599/1550.Three Consecutive Odds/Solution.cpp +++ b/solution/1500-1599/1550.Three Consecutive Odds/Solution.cpp @@ -2,13 +2,15 @@ class Solution { public: bool threeConsecutiveOdds(vector& arr) { int cnt = 0; - for (int v : arr) { - if (v & 1) - ++cnt; - else + for (int x : arr) { + if (x & 1) { + if (++cnt == 3) { + return true; + } + } else { cnt = 0; - if (cnt == 3) return true; + } } return false; } -}; \ No newline at end of file +}; From 9e0b1288aceb95cd312694193a539b4ca45e76b8 Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Tue, 2 Jul 2024 08:45:17 +0800 Subject: [PATCH 08/13] Update Solution.go --- .../1550.Three Consecutive Odds/Solution.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/solution/1500-1599/1550.Three Consecutive Odds/Solution.go b/solution/1500-1599/1550.Three Consecutive Odds/Solution.go index ffcb2363af09c..e08ef5207890b 100644 --- a/solution/1500-1599/1550.Three Consecutive Odds/Solution.go +++ b/solution/1500-1599/1550.Three Consecutive Odds/Solution.go @@ -1,14 +1,14 @@ func threeConsecutiveOdds(arr []int) bool { cnt := 0 - for _, v := range arr { - if v%2 == 1 { + for _, x := range arr { + if x&1 == 1 { cnt++ + if cnt == 3 { + return true + } } else { cnt = 0 } - if cnt == 3 { - return true - } } return false -} \ No newline at end of file +} From ee6f6a1683bd52f07a27d2ebe16adb54f9ee635b Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Tue, 2 Jul 2024 08:45:26 +0800 Subject: [PATCH 09/13] Update Solution.ts --- .../1500-1599/1550.Three Consecutive Odds/Solution.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/solution/1500-1599/1550.Three Consecutive Odds/Solution.ts b/solution/1500-1599/1550.Three Consecutive Odds/Solution.ts index faa220eddedf9..6d7b3aa0cd67f 100644 --- a/solution/1500-1599/1550.Three Consecutive Odds/Solution.ts +++ b/solution/1500-1599/1550.Three Consecutive Odds/Solution.ts @@ -1,14 +1,13 @@ function threeConsecutiveOdds(arr: number[]): boolean { let cnt = 0; - for (const v of arr) { - if (v & 1) { - ++cnt; + for (const x of arr) { + if (x & 1) { + if (++cnt == 3) { + return true; + } } else { cnt = 0; } - if (cnt == 3) { - return true; - } } return false; } From 9bd3798836a7400218dd53fa72bfa8b4a3679ec2 Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Tue, 2 Jul 2024 08:45:35 +0800 Subject: [PATCH 10/13] Update Solution2.py --- solution/1500-1599/1550.Three Consecutive Odds/Solution2.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/solution/1500-1599/1550.Three Consecutive Odds/Solution2.py b/solution/1500-1599/1550.Three Consecutive Odds/Solution2.py index a0fa200a72249..a30985ae73238 100644 --- a/solution/1500-1599/1550.Three Consecutive Odds/Solution2.py +++ b/solution/1500-1599/1550.Three Consecutive Odds/Solution2.py @@ -1,6 +1,3 @@ class Solution: def threeConsecutiveOdds(self, arr: List[int]) -> bool: - for i in range(len(arr) - 2): - if arr[i] % 2 + arr[i + 1] % 2 + arr[i + 2] % 2 == 3: - return True - return False + return any(x & arr[i + 1] & arr[i + 2] & 1 for i, x in enumerate(arr[:-2])) From 95e5e24dbd5f01d64a04b24bca1ce00171c1d283 Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Tue, 2 Jul 2024 08:45:46 +0800 Subject: [PATCH 11/13] Create Solution2.java --- .../1550.Three Consecutive Odds/Solution2.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 solution/1500-1599/1550.Three Consecutive Odds/Solution2.java diff --git a/solution/1500-1599/1550.Three Consecutive Odds/Solution2.java b/solution/1500-1599/1550.Three Consecutive Odds/Solution2.java new file mode 100644 index 0000000000000..f32544742b00e --- /dev/null +++ b/solution/1500-1599/1550.Three Consecutive Odds/Solution2.java @@ -0,0 +1,10 @@ +class Solution { + public boolean threeConsecutiveOdds(int[] arr) { + for (int i = 2, n = arr.length; i < n; ++i) { + if ((arr[i - 2] & arr[i - 1] & arr[i] & 1) == 1) { + return true; + } + } + return false; + } +} From 99b29a5f14b00a7ba8c680af2fe97af95ecf39a2 Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Tue, 2 Jul 2024 08:45:56 +0800 Subject: [PATCH 12/13] Create Solution2.cpp --- .../1550.Three Consecutive Odds/Solution2.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 solution/1500-1599/1550.Three Consecutive Odds/Solution2.cpp diff --git a/solution/1500-1599/1550.Three Consecutive Odds/Solution2.cpp b/solution/1500-1599/1550.Three Consecutive Odds/Solution2.cpp new file mode 100644 index 0000000000000..6b627251bc4bf --- /dev/null +++ b/solution/1500-1599/1550.Three Consecutive Odds/Solution2.cpp @@ -0,0 +1,11 @@ +class Solution { +public: + bool threeConsecutiveOdds(vector& arr) { + for (int i = 2, n = arr.size(); i < n; ++i) { + if (arr[i - 2] & arr[i - 1] & arr[i] & 1) { + return true; + } + } + return false; + } +}; From 1db8e5bae22621ea6879e207de83b0f5ca55a7df Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Tue, 2 Jul 2024 08:46:06 +0800 Subject: [PATCH 13/13] Create Solution2.go --- .../1500-1599/1550.Three Consecutive Odds/Solution2.go | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 solution/1500-1599/1550.Three Consecutive Odds/Solution2.go diff --git a/solution/1500-1599/1550.Three Consecutive Odds/Solution2.go b/solution/1500-1599/1550.Three Consecutive Odds/Solution2.go new file mode 100644 index 0000000000000..69f0d8b3ac93d --- /dev/null +++ b/solution/1500-1599/1550.Three Consecutive Odds/Solution2.go @@ -0,0 +1,8 @@ +func threeConsecutiveOdds(arr []int) bool { + for i, n := 2, len(arr); i < n; i++ { + if arr[i-2]&arr[i-1]&arr[i]&1 == 1 { + return true + } + } + return false +}