Skip to content

Commit d80c509

Browse files
Merge branch 'main' into main
2 parents 0a2f2fd + c38b9e2 commit d80c509

File tree

9 files changed

+206
-0
lines changed

9 files changed

+206
-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+
}

solution/2600-2699/2683.Neighboring Bitwise XOR/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,38 @@ function doesValidArrayExist(derived: number[]): boolean {
160160
}
161161
```
162162

163+
#### Rust
164+
165+
```rust
166+
impl Solution {
167+
pub fn does_valid_array_exist(derived: Vec<i32>) -> bool {
168+
derived.iter().fold(0, |acc, &x| acc ^ x) == 0
169+
}
170+
}
171+
```
172+
173+
#### JavaScript
174+
175+
```js
176+
/**
177+
* @param {number[]} derived
178+
* @return {boolean}
179+
*/
180+
var doesValidArrayExist = function (derived) {
181+
return derived.reduce((acc, x) => acc ^ x) === 0;
182+
};
183+
```
184+
185+
#### C#
186+
187+
```cs
188+
public class Solution {
189+
public bool DoesValidArrayExist(int[] derived) {
190+
return derived.Aggregate(0, (acc, x) => acc ^ x) == 0;
191+
}
192+
}
193+
```
194+
163195
<!-- tabs:end -->
164196

165197
<!-- solution:end -->

solution/2600-2699/2683.Neighboring Bitwise XOR/README_EN.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,38 @@ function doesValidArrayExist(derived: number[]): boolean {
161161
}
162162
```
163163

164+
#### Rust
165+
166+
```rust
167+
impl Solution {
168+
pub fn does_valid_array_exist(derived: Vec<i32>) -> bool {
169+
derived.iter().fold(0, |acc, &x| acc ^ x) == 0
170+
}
171+
}
172+
```
173+
174+
#### JavaScript
175+
176+
```js
177+
/**
178+
* @param {number[]} derived
179+
* @return {boolean}
180+
*/
181+
var doesValidArrayExist = function (derived) {
182+
return derived.reduce((acc, x) => acc ^ x) === 0;
183+
};
184+
```
185+
186+
#### C#
187+
188+
```cs
189+
public class Solution {
190+
public bool DoesValidArrayExist(int[] derived) {
191+
return derived.Aggregate(0, (acc, x) => acc ^ x) == 0;
192+
}
193+
}
194+
```
195+
164196
<!-- tabs:end -->
165197

166198
<!-- solution:end -->
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class Solution {
2+
public bool DoesValidArrayExist(int[] derived) {
3+
return derived.Aggregate(0, (acc, x) => acc ^ x) == 0;
4+
}
5+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* @param {number[]} derived
3+
* @return {boolean}
4+
*/
5+
var doesValidArrayExist = function (derived) {
6+
return derived.reduce((acc, x) => acc ^ x) === 0;
7+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
impl Solution {
2+
pub fn does_valid_array_exist(derived: Vec<i32>) -> bool {
3+
derived.iter().fold(0, |acc, &x| acc ^ x) == 0
4+
}
5+
}

0 commit comments

Comments
 (0)