diff --git a/solution/2400-2499/2419.Longest Subarray With Maximum Bitwise AND/README.md b/solution/2400-2499/2419.Longest Subarray With Maximum Bitwise AND/README.md index 1de9e92ed8677..f5b167c632c59 100644 --- a/solution/2400-2499/2419.Longest Subarray With Maximum Bitwise AND/README.md +++ b/solution/2400-2499/2419.Longest Subarray With Maximum Bitwise AND/README.md @@ -217,6 +217,51 @@ var longestSubarray = function (nums) { }; ``` +#### C# + +```cs +public class Solution { + public int LongestSubarray(int[] nums) { + int mx = nums.Max(); + int ans = 0, cnt = 0; + foreach (int x in nums) { + if (x == mx) { + ans = Math.Max(ans, ++cnt); + } else { + cnt = 0; + } + } + return ans; + } +} +``` + +#### PHP + +```php +class Solution { + /** + * @param Integer[] $nums + * @return Integer + */ + function longestSubarray($nums) { + $mx = max($nums); + $ans = 0; + $cnt = 0; + + foreach ($nums as $x) { + if ($x == $mx) { + $ans = max($ans, ++$cnt); + } else { + $cnt = 0; + } + } + + return $ans; + } +} +``` + diff --git a/solution/2400-2499/2419.Longest Subarray With Maximum Bitwise AND/README_EN.md b/solution/2400-2499/2419.Longest Subarray With Maximum Bitwise AND/README_EN.md index c95729b44a910..e6d663d5fd01b 100644 --- a/solution/2400-2499/2419.Longest Subarray With Maximum Bitwise AND/README_EN.md +++ b/solution/2400-2499/2419.Longest Subarray With Maximum Bitwise AND/README_EN.md @@ -215,6 +215,51 @@ var longestSubarray = function (nums) { }; ``` +#### C# + +```cs +public class Solution { + public int LongestSubarray(int[] nums) { + int mx = nums.Max(); + int ans = 0, cnt = 0; + foreach (int x in nums) { + if (x == mx) { + ans = Math.Max(ans, ++cnt); + } else { + cnt = 0; + } + } + return ans; + } +} +``` + +#### PHP + +```php +class Solution { + /** + * @param Integer[] $nums + * @return Integer + */ + function longestSubarray($nums) { + $mx = max($nums); + $ans = 0; + $cnt = 0; + + foreach ($nums as $x) { + if ($x == $mx) { + $ans = max($ans, ++$cnt); + } else { + $cnt = 0; + } + } + + return $ans; + } +} +``` + diff --git a/solution/2400-2499/2419.Longest Subarray With Maximum Bitwise AND/Solution.cs b/solution/2400-2499/2419.Longest Subarray With Maximum Bitwise AND/Solution.cs new file mode 100644 index 0000000000000..43ec08525037c --- /dev/null +++ b/solution/2400-2499/2419.Longest Subarray With Maximum Bitwise AND/Solution.cs @@ -0,0 +1,14 @@ +public class Solution { + public int LongestSubarray(int[] nums) { + int mx = nums.Max(); + int ans = 0, cnt = 0; + foreach (int x in nums) { + if (x == mx) { + ans = Math.Max(ans, ++cnt); + } else { + cnt = 0; + } + } + return ans; + } +} diff --git a/solution/2400-2499/2419.Longest Subarray With Maximum Bitwise AND/Solution.php b/solution/2400-2499/2419.Longest Subarray With Maximum Bitwise AND/Solution.php new file mode 100644 index 0000000000000..390d95d2acbd8 --- /dev/null +++ b/solution/2400-2499/2419.Longest Subarray With Maximum Bitwise AND/Solution.php @@ -0,0 +1,21 @@ +class Solution { + /** + * @param Integer[] $nums + * @return Integer + */ + function longestSubarray($nums) { + $mx = max($nums); + $ans = 0; + $cnt = 0; + + foreach ($nums as $x) { + if ($x == $mx) { + $ans = max($ans, ++$cnt); + } else { + $cnt = 0; + } + } + + return $ans; + } +} \ No newline at end of file