Skip to content

Commit ee8884b

Browse files
authored
feat: add solutions to lc problem: No.2419 (#4605)
No.2419.Longest Subarray With Maximum Bitwise AND
1 parent 5058ba8 commit ee8884b

File tree

4 files changed

+125
-0
lines changed

4 files changed

+125
-0
lines changed

solution/2400-2499/2419.Longest Subarray With Maximum Bitwise AND/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,51 @@ var longestSubarray = function (nums) {
217217
};
218218
```
219219

220+
#### C#
221+
222+
```cs
223+
public class Solution {
224+
public int LongestSubarray(int[] nums) {
225+
int mx = nums.Max();
226+
int ans = 0, cnt = 0;
227+
foreach (int x in nums) {
228+
if (x == mx) {
229+
ans = Math.Max(ans, ++cnt);
230+
} else {
231+
cnt = 0;
232+
}
233+
}
234+
return ans;
235+
}
236+
}
237+
```
238+
239+
#### PHP
240+
241+
```php
242+
class Solution {
243+
/**
244+
* @param Integer[] $nums
245+
* @return Integer
246+
*/
247+
function longestSubarray($nums) {
248+
$mx = max($nums);
249+
$ans = 0;
250+
$cnt = 0;
251+
252+
foreach ($nums as $x) {
253+
if ($x == $mx) {
254+
$ans = max($ans, ++$cnt);
255+
} else {
256+
$cnt = 0;
257+
}
258+
}
259+
260+
return $ans;
261+
}
262+
}
263+
```
264+
220265
<!-- tabs:end -->
221266

222267
<!-- solution:end -->

solution/2400-2499/2419.Longest Subarray With Maximum Bitwise AND/README_EN.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,51 @@ var longestSubarray = function (nums) {
215215
};
216216
```
217217

218+
#### C#
219+
220+
```cs
221+
public class Solution {
222+
public int LongestSubarray(int[] nums) {
223+
int mx = nums.Max();
224+
int ans = 0, cnt = 0;
225+
foreach (int x in nums) {
226+
if (x == mx) {
227+
ans = Math.Max(ans, ++cnt);
228+
} else {
229+
cnt = 0;
230+
}
231+
}
232+
return ans;
233+
}
234+
}
235+
```
236+
237+
#### PHP
238+
239+
```php
240+
class Solution {
241+
/**
242+
* @param Integer[] $nums
243+
* @return Integer
244+
*/
245+
function longestSubarray($nums) {
246+
$mx = max($nums);
247+
$ans = 0;
248+
$cnt = 0;
249+
250+
foreach ($nums as $x) {
251+
if ($x == $mx) {
252+
$ans = max($ans, ++$cnt);
253+
} else {
254+
$cnt = 0;
255+
}
256+
}
257+
258+
return $ans;
259+
}
260+
}
261+
```
262+
218263
<!-- tabs:end -->
219264

220265
<!-- solution:end -->
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public class Solution {
2+
public int LongestSubarray(int[] nums) {
3+
int mx = nums.Max();
4+
int ans = 0, cnt = 0;
5+
foreach (int x in nums) {
6+
if (x == mx) {
7+
ans = Math.Max(ans, ++cnt);
8+
} else {
9+
cnt = 0;
10+
}
11+
}
12+
return ans;
13+
}
14+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
/**
3+
* @param Integer[] $nums
4+
* @return Integer
5+
*/
6+
function longestSubarray($nums) {
7+
$mx = max($nums);
8+
$ans = 0;
9+
$cnt = 0;
10+
11+
foreach ($nums as $x) {
12+
if ($x == $mx) {
13+
$ans = max($ans, ++$cnt);
14+
} else {
15+
$cnt = 0;
16+
}
17+
}
18+
19+
return $ans;
20+
}
21+
}

0 commit comments

Comments
 (0)